File: array-elemental-calls-2.f90

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (196 lines) | stat: -rw-r--r-- 9,666 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
! RUN: bbc -o - -emit-fir %s | FileCheck %s

! Test lowering of operations sub-expression inside elemental call arguments.
! This tests array contexts where an address is needed for each element (for
! the argument), but part of the array sub-expression must be lowered by value
! (for the operation)

module test_ops
  interface
    integer elemental function elem_func(i)
      integer, intent(in) :: i
    end function
    integer elemental function elem_func_logical(l)
      logical(8), intent(in) :: l
    end function
    integer elemental function elem_func_logical4(l)
      logical, intent(in) :: l
    end function
    integer elemental function elem_func_real(x)
      real(8), value :: x
    end function
  end interface
  integer :: i(10), j(10), iscalar
  logical(8) :: a(10), b(10)
  real(8) :: x(10), y(10)
  complex(8) :: z1(10), z2

contains
! CHECK-LABEL: func @_QMtest_opsPcheck_binary_ops() {
subroutine check_binary_ops()
  print *,  elem_func(i+j)
! CHECK:  %[[VAL_0:.*]] = fir.alloca i32
! CHECK:  fir.do_loop
! CHECK:  %[[VAL_25:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10xi32>, index) -> i32
! CHECK:  %[[VAL_26:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10xi32>, index) -> i32
! CHECK:  %[[VAL_27:.*]] = arith.addi %[[VAL_25]], %[[VAL_26]] : i32
! CHECK:  fir.store %[[VAL_27]] to %[[VAL_0]] : !fir.ref<i32>
! CHECK:  fir.call @_QPelem_func(%[[VAL_0]]) {{.*}}: (!fir.ref<i32>) -> i32
end subroutine

! CHECK-LABEL: func @_QMtest_opsPcheck_binary_ops_2() {
subroutine check_binary_ops_2()
  print *,  elem_func(i*iscalar)
! CHECK:  %[[VAL_0:.*]] = fir.alloca i32
! CHECK:  %[[VAL_13:.*]] = fir.load %{{.*}} : !fir.ref<i32>
! CHECK:  fir.do_loop
! CHECK:  %[[VAL_25:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10xi32>, index) -> i32
! CHECK:  %[[VAL_27:.*]] = arith.muli %[[VAL_25]], %[[VAL_13]] : i32
! CHECK:  fir.store %[[VAL_27]] to %[[VAL_0]] : !fir.ref<i32>
! CHECK:  fir.call @_QPelem_func(%[[VAL_0]]) {{.*}}: (!fir.ref<i32>) -> i32
end subroutine

! CHECK-LABEL: func @_QMtest_opsPcheck_negate() {
subroutine check_negate()
  print *,  elem_func(-i)
! CHECK:  %[[VAL_0:.*]] = fir.alloca i32
! CHECK:  fir.do_loop
! CHECK:  %[[VAL_21:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10xi32>, index) -> i32
! CHECK:  %[[VAL_22:.*]] = arith.constant 0 : i32
! CHECK:  %[[VAL_23:.*]] = arith.subi %[[VAL_22]], %[[VAL_21]] : i32
! CHECK:  fir.store %[[VAL_23]] to %[[VAL_0]] : !fir.ref<i32>
! CHECK:  fir.call @_QPelem_func(%[[VAL_0]]) {{.*}}: (!fir.ref<i32>) -> i32
end subroutine

! CHECK-LABEL: func @_QMtest_opsPcheck_convert() {
subroutine check_convert()
  print *,  elem_func(int(x))
! CHECK:  %[[VAL_0:.*]] = fir.alloca i32
! CHECK:  fir.do_loop
! CHECK:  %[[VAL_21:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10xf64>, index) -> f64
! CHECK:  %[[VAL_22:.*]] = fir.convert %[[VAL_21]] : (f64) -> i32
! CHECK:  fir.store %[[VAL_22]] to %[[VAL_0]] : !fir.ref<i32>
! CHECK:  fir.call @_QPelem_func(%[[VAL_0]]) {{.*}}: (!fir.ref<i32>) -> i32
end subroutine

! CHECK-LABEL: func @_QMtest_opsPcheck_exteremum() {
subroutine check_exteremum()
  print *,  elem_func(min(i, j))
! CHECK:  %[[VAL_0:.*]] = fir.alloca i32
! CHECK:  fir.do_loop
! CHECK:  %[[VAL_25:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10xi32>, index) -> i32
! CHECK:  %[[VAL_26:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10xi32>, index) -> i32
! CHECK:  %[[VAL_27:.*]] = arith.cmpi slt, %[[VAL_25]], %[[VAL_26]] : i32
! CHECK:  %[[VAL_28:.*]] = arith.select %[[VAL_27]], %[[VAL_25]], %[[VAL_26]] : i32
! CHECK:  fir.store %[[VAL_28]] to %[[VAL_0]] : !fir.ref<i32>
! CHECK:  fir.call @_QPelem_func(%[[VAL_0]]) {{.*}}: (!fir.ref<i32>) -> i32
end subroutine

! CHECK-LABEL: func @_QMtest_opsPcheck_logical_unary_ops() {
subroutine check_logical_unary_ops()
  print *,  elem_func_logical(.not.b)
! CHECK:  %[[VAL_0:.*]] = fir.alloca !fir.logical<8>
! CHECK:  %[[VAL_12:.*]] = arith.constant true
! CHECK:  fir.do_loop
! CHECK:  %[[VAL_22:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10x!fir.logical<8>>, index) -> !fir.logical<8>
! CHECK:  %[[VAL_23:.*]] = fir.convert %[[VAL_22]] : (!fir.logical<8>) -> i1
! CHECK:  %[[VAL_24:.*]] = arith.xori %[[VAL_23]], %[[VAL_12]] : i1
! CHECK:  %[[VAL_25:.*]] = fir.convert %[[VAL_24]] : (i1) -> !fir.logical<8>
! CHECK:  fir.store %[[VAL_25]] to %[[VAL_0]] : !fir.ref<!fir.logical<8>>
! CHECK:  fir.call @_QPelem_func_logical(%[[VAL_0]]) {{.*}}: (!fir.ref<!fir.logical<8>>) -> i32
end subroutine

! CHECK-LABEL: func @_QMtest_opsPcheck_logical_binary_ops() {
subroutine check_logical_binary_ops()
  print *,  elem_func_logical(a.eqv.b)
! CHECK:  %[[VAL_0:.*]] = fir.alloca !fir.logical<8>
! CHECK:  fir.do_loop
! CHECK:  %[[VAL_25:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10x!fir.logical<8>>, index) -> !fir.logical<8>
! CHECK:  %[[VAL_26:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10x!fir.logical<8>>, index) -> !fir.logical<8>
! CHECK:  %[[VAL_27:.*]] = fir.convert %[[VAL_25]] : (!fir.logical<8>) -> i1
! CHECK:  %[[VAL_28:.*]] = fir.convert %[[VAL_26]] : (!fir.logical<8>) -> i1
! CHECK:  %[[VAL_29:.*]] = arith.cmpi eq, %[[VAL_27]], %[[VAL_28]] : i1
! CHECK:  %[[VAL_30:.*]] = fir.convert %[[VAL_29]] : (i1) -> !fir.logical<8>
! CHECK:  fir.store %[[VAL_30]] to %[[VAL_0]] : !fir.ref<!fir.logical<8>>
! CHECK:  fir.call @_QPelem_func_logical(%[[VAL_0]]) {{.*}}: (!fir.ref<!fir.logical<8>>) -> i32
end subroutine

! CHECK-LABEL: func @_QMtest_opsPcheck_compare() {
subroutine check_compare()
  print *,  elem_func_logical4(x.lt.y)
! CHECK:  %[[VAL_0:.*]] = fir.alloca !fir.logical<4>
! CHECK:  fir.do_loop
! CHECK:  %[[VAL_25:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10xf64>, index) -> f64
! CHECK:  %[[VAL_26:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10xf64>, index) -> f64
! CHECK:  %[[VAL_27:.*]] = arith.cmpf olt, %[[VAL_25]], %[[VAL_26]] : f64
! CHECK:  %[[VAL_28:.*]] = fir.convert %[[VAL_27]] : (i1) -> !fir.logical<4>
! CHECK:  fir.store %[[VAL_28]] to %[[VAL_0]] : !fir.ref<!fir.logical<4>>
! CHECK:  fir.call @_QPelem_func_logical4(%[[VAL_0]]) {{.*}}: (!fir.ref<!fir.logical<4>>) -> i32
end subroutine

! CHECK-LABEL: func @_QMtest_opsPcheck_pow() {
subroutine check_pow()
  print *,  elem_func_real(x**y)
! CHECK:  fir.do_loop
! CHECK:  %[[VAL_25:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10xf64>, index) -> f64
! CHECK:  %[[VAL_26:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10xf64>, index) -> f64
! CHECK:  %[[VAL_27:.*]] = math.powf %[[VAL_25]], %[[VAL_26]] {{.*}}: f64
! CHECK:  %[[VAL_28:.*]] = fir.call @_QPelem_func_real(%[[VAL_27]]) {{.*}}: (f64) -> i32
end subroutine

! CHECK-LABEL: func @_QMtest_opsPcheck_cmplx_part() {
subroutine check_cmplx_part()
  print *,  elem_func_real(AIMAG(z1 + z2))
! CHECK:  %[[VAL_13:.*]] = fir.load %{{.*}} : !fir.ref<!fir.complex<8>>
! CHECK:  fir.do_loop
! CHECK:  %[[VAL_23:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10x!fir.complex<8>>, index) -> !fir.complex<8>
! CHECK:  %[[VAL_24:.*]] = fir.addc %[[VAL_23]], %[[VAL_13]] : !fir.complex<8>
! CHECK:  %[[VAL_25:.*]] = fir.extract_value %[[VAL_24]], [1 : index] : (!fir.complex<8>) -> f64
! CHECK:  fir.call @_QPelem_func_real(%[[VAL_25]]) {{.*}}: (f64) -> i32
end subroutine

! CHECK-LABEL: func @_QMtest_opsPcheck_parentheses() {
subroutine check_parentheses()
  print *,  elem_func_real((x))
! CHECK:  fir.do_loop
! CHECK:  %[[VAL_21:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10xf64>, index) -> f64
! CHECK:  %[[VAL_22:.*]] = fir.no_reassoc %[[VAL_21]] : f64
! CHECK:  fir.call @_QPelem_func_real(%[[VAL_22]]) {{.*}}: (f64) -> i32
end subroutine

! CHECK-LABEL: func @_QMtest_opsPcheck_parentheses_logical() {
subroutine check_parentheses_logical()
  print *,  elem_func_logical((a))
! CHECK:  %[[VAL_0:.*]] = fir.alloca !fir.logical<8>
! CHECK:  fir.do_loop
! CHECK:  %[[VAL_21:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10x!fir.logical<8>>, index) -> !fir.logical<8>
! CHECK:  %[[VAL_22:.*]] = fir.no_reassoc %[[VAL_21]] : !fir.logical<8>
! CHECK:  fir.store %[[VAL_22]] to %[[VAL_0]] : !fir.ref<!fir.logical<8>>
! CHECK:  fir.call @_QPelem_func_logical(%[[VAL_0]]) {{.*}}: (!fir.ref<!fir.logical<8>>) -> i32
end subroutine

subroutine check_parentheses_derived(a)
  type t
    integer :: i
  end type  
  interface
    integer elemental function elem_func_derived(x)
      import :: t
      type(t), intent(in) :: x
    end function
  end interface
  type(t), pointer :: a(:)
  print *,  elem_func_derived((a))
! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.type<_QMtest_opsFcheck_parentheses_derivedTt{i:i32}>
! CHECK: fir.do_loop
! CHECK: %[[VAL_21:.*]] = fir.array_access %{{.}}, %{{.*}}
! CHECK: %[[VAL_22:.*]] = fir.no_reassoc %[[VAL_21]] : !fir.ref<!fir.type<_QMtest_opsFcheck_parentheses_derivedTt{i:i32}>>
! CHECK: %[[FIELD:.*]] = fir.field_index i, !fir.type<_QMtest_opsFcheck_parentheses_derivedTt{i:i32}>
! CHECK: %[[FROM:.*]] = fir.coordinate_of %[[VAL_22]], %[[FIELD]] : (!fir.ref<!fir.type<_QMtest_opsFcheck_parentheses_derivedTt{i:i32}>>, !fir.field) -> !fir.ref<i32>
! CHECK: %[[FIELD2:.*]] = fir.field_index i, !fir.type<_QMtest_opsFcheck_parentheses_derivedTt{i:i32}>
! CHECK: %[[TO:.*]] = fir.coordinate_of %[[VAL_0]], %[[FIELD2]] : (!fir.ref<!fir.type<_QMtest_opsFcheck_parentheses_derivedTt{i:i32}>>, !fir.field) -> !fir.ref<i32>
! CHECK: %[[VAL:.*]] = fir.load %[[FROM]] : !fir.ref<i32>
! CHECK: fir.store %[[VAL]] to %[[TO]] : !fir.ref<i32>
! CHECK: %{{.*}} = fir.call @_QPelem_func_derived(%[[VAL_0]]) {{.*}}: (!fir.ref<!fir.type<_QMtest_opsFcheck_parentheses_derivedTt{i:i32}>>) -> i32
end subroutine
end module