[Transforms] Silence a warning in SROA.cpp (NFC)
[llvm-project.git] / flang / test / Lower / HLFIR / elemental-intrinsics.f90
blobdd79688663cba484a7186508c4fb877b5fbd83d1
1 ! Test lowering of intrinsic elemental procedure reference to HLFIR
2 ! The goal here is not to test every intrinsics, it is to test the
3 ! lowering framework for elemental intrinsics. This test various
4 ! intrinsics that have different number or arguments and argument types.
5 ! RUN: bbc -emit-hlfir -o - %s | FileCheck %s
7 subroutine simple_elemental(x,y)
8 real :: x(100), y(100)
9 x = acos(y)
10 end subroutine
11 ! CHECK-LABEL: func.func @_QPsimple_elemental(
12 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]](%[[VAL_3:[a-z0-9]*]]) {{.*}}Ex
13 ! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_1:[a-z0-9]*]](%[[VAL_6:[a-z0-9]*]]) {{.*}}Ey
14 ! CHECK: %[[VAL_8:.*]] = hlfir.elemental %[[VAL_6]] unordered : (!fir.shape<1>) -> !hlfir.expr<100xf32> {
15 ! CHECK: ^bb0(%[[VAL_9:.*]]: index):
16 ! CHECK: %[[VAL_10:.*]] = hlfir.designate %[[VAL_7]]#0 (%[[VAL_9]]) : (!fir.ref<!fir.array<100xf32>>, index) -> !fir.ref<f32>
17 ! CHECK: %[[VAL_11:.*]] = fir.load %[[VAL_10]] : !fir.ref<f32>
18 ! CHECK: %[[VAL_12:.*]] = fir.call @acosf(%[[VAL_11]]) fastmath<contract> : (f32) -> f32
19 ! CHECK: hlfir.yield_element %[[VAL_12]] : f32
20 ! CHECK: }
21 ! CHECK: hlfir.assign
22 ! CHECK: hlfir.destroy %[[VAL_8]]
24 subroutine elemental_mixed_args(x,y, scalar)
25 real :: x(100), y(100), scalar
26 x = atan2(x, scalar)
27 end subroutine
28 ! CHECK-LABEL: func.func @_QPelemental_mixed_args(
29 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2:[a-z0-9]*]] {{.*}}Escalar
30 ! CHECK: %[[VAL_4:.*]] = arith.constant 100 : index
31 ! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_4]] : (index) -> !fir.shape<1>
32 ! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]](%[[VAL_5:[a-z0-9]*]]) {{.*}}Ex
33 ! CHECK: %[[VAL_7:.*]] = arith.constant 100 : index
34 ! CHECK: %[[VAL_8:.*]] = fir.shape %[[VAL_7]] : (index) -> !fir.shape<1>
35 ! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_1:[a-z0-9]*]](%[[VAL_8:[a-z0-9]*]]) {{.*}}Ey
36 ! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<f32>
37 ! CHECK: %[[VAL_11:.*]] = hlfir.elemental %[[VAL_5]] unordered : (!fir.shape<1>) -> !hlfir.expr<100xf32> {
38 ! CHECK: ^bb0(%[[VAL_12:.*]]: index):
39 ! CHECK: %[[VAL_13:.*]] = hlfir.designate %[[VAL_6]]#0 (%[[VAL_12]]) : (!fir.ref<!fir.array<100xf32>>, index) -> !fir.ref<f32>
40 ! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_13]] : !fir.ref<f32>
41 ! CHECK: %[[VAL_15:.*]] = math.atan2 %[[VAL_14]], %[[VAL_10]] fastmath<contract> : f32
42 ! CHECK: hlfir.yield_element %[[VAL_15]] : f32
43 ! CHECK: }
44 ! CHECK: hlfir.assign
45 ! CHECK: hlfir.destroy %[[VAL_11]]
47 subroutine elemental_assumed_shape_arg(x)
48 real :: x(:)
49 print *, sin(x)
50 end subroutine
51 ! CHECK-LABEL: func.func @_QPelemental_assumed_shape_arg(
52 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ex
53 ! CHECK: %[[VAL_7:.*]] = arith.constant 0 : index
54 ! CHECK: %[[VAL_8:.*]]:3 = fir.box_dims %[[VAL_1]]#0, %[[VAL_7]] : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
55 ! CHECK: %[[VAL_9:.*]] = fir.shape %[[VAL_8]]#1 : (index) -> !fir.shape<1>
56 ! CHECK: %[[VAL_10:.*]] = hlfir.elemental %[[VAL_9]] unordered : (!fir.shape<1>) -> !hlfir.expr<?xf32> {
57 ! CHECK: ^bb0(%[[VAL_11:.*]]: index):
58 ! CHECK: %[[VAL_12:.*]] = hlfir.designate %[[VAL_1]]#0 (%[[VAL_11]]) : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32>
59 ! CHECK: %[[VAL_13:.*]] = fir.load %[[VAL_12]] : !fir.ref<f32>
60 ! CHECK: %[[VAL_14:.*]] = math.sin %[[VAL_13]] fastmath<contract> : f32
61 ! CHECK: hlfir.yield_element %[[VAL_14]] : f32
62 ! CHECK: }
63 ! CHECK: fir.call
64 ! CHECK: hlfir.destroy %[[VAL_10]]
66 subroutine elemental_with_char_args(x,y)
67 character(*) :: x(100), y(:)
68 print *, scan(x, y)
69 end subroutine
70 ! CHECK-LABEL: func.func @_QPelemental_with_char_args(
71 ! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_3:[a-z0-9]*]](%[[VAL_5:[a-z0-9]*]]) typeparams %[[VAL_2:[a-z0-9]*]]#1 {{.*}}Ex
72 ! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_1:[a-z0-9]*]] {{.*}}Ey
73 ! CHECK: %[[VAL_13:.*]] = hlfir.elemental %[[VAL_5]] unordered : (!fir.shape<1>) -> !hlfir.expr<100xi32> {
74 ! CHECK: ^bb0(%[[VAL_14:.*]]: index):
75 ! CHECK: %[[VAL_15:.*]] = hlfir.designate %[[VAL_6]]#0 (%[[VAL_14]]) typeparams %[[VAL_2]]#1 : (!fir.box<!fir.array<100x!fir.char<1,?>>>, index, index) -> !fir.boxchar<1>
76 ! CHECK: %[[VAL_18:.*]]:2 = fir.unboxchar %[[VAL_15]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
77 ! CHECK: %[[VAL_16:.*]] = fir.box_elesize %[[VAL_7]]#1 : (!fir.box<!fir.array<?x!fir.char<1,?>>>) -> index
78 ! CHECK: %[[VAL_17:.*]] = hlfir.designate %[[VAL_7]]#0 (%[[VAL_14]]) typeparams %[[VAL_16]] : (!fir.box<!fir.array<?x!fir.char<1,?>>>, index, index) -> !fir.boxchar<1>
79 ! CHECK: %[[VAL_19:.*]]:2 = fir.unboxchar %[[VAL_17]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
80 ! CHECK: %[[VAL_20:.*]] = arith.constant false
81 ! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_18]]#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<i8>
82 ! CHECK: %[[VAL_22:.*]] = fir.convert %[[VAL_2]]#1 : (index) -> i64
83 ! CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_19]]#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<i8>
84 ! CHECK: %[[VAL_24:.*]] = fir.convert %[[VAL_16]] : (index) -> i64
85 ! CHECK: %[[VAL_25:.*]] = fir.call @_FortranAScan1(%[[VAL_21]], %[[VAL_22]], %[[VAL_23]], %[[VAL_24]], %[[VAL_20]])
86 ! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_25]] : (i64) -> i32
87 ! CHECK: hlfir.yield_element %[[VAL_26]] : i32
88 ! CHECK: }
89 ! CHECK: fir.call
90 ! CHECK: hlfir.destroy %[[VAL_13]]
93 ! -----------------------------------------------------------------------------
94 ! Test elemental character intrinsics with non compile time constant result
95 ! length.
96 ! -----------------------------------------------------------------------------
98 subroutine test_adjustl(x)
99 character(*) :: x(100)
100 call bar(adjustl(x))
101 end subroutine
102 ! CHECK-LABEL: func.func @_QPtest_adjustl(
103 ! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_3:.*]](%[[VAL_5:[a-z0-9]*]]) typeparams %[[VAL_2:[a-z0-9]*]]#1 {{.*}}Ex
104 ! CHECK: %[[VAL_7:.*]] = hlfir.elemental %[[VAL_5]] typeparams %[[VAL_2]]#1 unordered : (!fir.shape<1>, index) -> !hlfir.expr<100x!fir.char<1,?>> {
105 ! CHECK: ^bb0(%[[VAL_8:.*]]: index):
106 ! CHECK: %[[VAL_9:.*]] = hlfir.designate %[[VAL_6]]#0 (%[[VAL_8]]) typeparams %[[VAL_2]]#1 : (!fir.box<!fir.array<100x!fir.char<1,?>>>, index, index) -> !fir.boxchar<1>
107 ! CHECK: fir.call @_FortranAAdjustl
108 ! CHECK: %[[VAL_24:.*]]:2 = hlfir.declare %{{.*}} typeparams %[[VAL_22:.*]] {uniq_name = ".tmp.intrinsic_result"} : (!fir.heap<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.heap<!fir.char<1,?>>)
109 ! CHECK: %[[VAL_25:.*]] = arith.constant true
110 ! CHECK: %[[VAL_26:.*]] = hlfir.as_expr %[[VAL_24]]#0 move %[[VAL_25]] : (!fir.boxchar<1>, i1) -> !hlfir.expr<!fir.char<1,?>>
111 ! CHECK: hlfir.yield_element %[[VAL_26]] : !hlfir.expr<!fir.char<1,?>>
112 ! CHECK: }
114 subroutine test_adjustr(x)
115 character(*) :: x(100)
116 call bar(adjustr(x))
117 end subroutine
118 ! CHECK-LABEL: func.func @_QPtest_adjustr(
119 ! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_3:.*]](%[[VAL_5:[a-z0-9]*]]) typeparams %[[VAL_2:[a-z0-9]*]]#1 {{.*}}Ex
120 ! CHECK: %[[VAL_7:.*]] = hlfir.elemental %[[VAL_5]] typeparams %[[VAL_2]]#1 unordered : (!fir.shape<1>, index) -> !hlfir.expr<100x!fir.char<1,?>> {
121 ! CHECK: ^bb0(%[[VAL_8:.*]]: index):
122 ! CHECK: %[[VAL_9:.*]] = hlfir.designate %[[VAL_6]]#0 (%[[VAL_8]]) typeparams %[[VAL_2]]#1 : (!fir.box<!fir.array<100x!fir.char<1,?>>>, index, index) -> !fir.boxchar<1>
123 ! CHECK: fir.call @_FortranAAdjustr
124 ! CHECK: %[[VAL_24:.*]]:2 = hlfir.declare %{{.*}} typeparams %[[VAL_22:.*]] {uniq_name = ".tmp.intrinsic_result"} : (!fir.heap<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.heap<!fir.char<1,?>>)
125 ! CHECK: %[[VAL_25:.*]] = arith.constant true
126 ! CHECK: %[[VAL_26:.*]] = hlfir.as_expr %[[VAL_24]]#0 move %[[VAL_25]] : (!fir.boxchar<1>, i1) -> !hlfir.expr<!fir.char<1,?>>
127 ! CHECK: hlfir.yield_element %[[VAL_26]] : !hlfir.expr<!fir.char<1,?>>
128 ! CHECK: }
130 subroutine test_merge(x, y, mask)
131 character(*) :: x(100), y(100)
132 logical :: mask(100)
133 call bar(merge(x, y, mask))
134 end subroutine
135 ! CHECK-LABEL: func.func @_QPtest_merge(
136 ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_2:[a-z0-9]*]](%[[VAL_4:[a-z0-9]*]]) {{.*}}Emask
137 ! CHECK: %[[VAL_10:.*]]:2 = hlfir.declare %[[VAL_7:[a-z0-9]*]](%[[VAL_9:[a-z0-9]*]]) typeparams %[[VAL_6:[a-z0-9]*]]#1 {{.*}}Ex
138 ! CHECK: %[[VAL_15:.*]]:2 = hlfir.declare %[[VAL_12:[a-z0-9]*]](%[[VAL_14:[a-z0-9]*]]) typeparams %[[VAL_11:[a-z0-9]*]]#1 {{.*}}Ey
139 ! CHECK: %[[VAL_16:.*]] = hlfir.elemental %[[VAL_9]] typeparams %[[VAL_6]]#1 unordered : (!fir.shape<1>, index) -> !hlfir.expr<100x!fir.char<1,?>> {
140 ! CHECK: ^bb0(%[[VAL_17:.*]]: index):
141 ! CHECK: %[[VAL_18:.*]] = hlfir.designate %[[VAL_10]]#0 (%[[VAL_17]]) typeparams %[[VAL_6]]#1 : (!fir.box<!fir.array<100x!fir.char<1,?>>>, index, index) -> !fir.boxchar<1>
142 ! CHECK: %[[VAL_21:.*]]:2 = fir.unboxchar %[[VAL_18]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
143 ! CHECK: %[[VAL_19:.*]] = hlfir.designate %[[VAL_15]]#0 (%[[VAL_17]]) typeparams %[[VAL_11]]#1 : (!fir.box<!fir.array<100x!fir.char<1,?>>>, index, index) -> !fir.boxchar<1>
144 ! CHECK: %[[VAL_22:.*]]:2 = fir.unboxchar %[[VAL_19]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
145 ! CHECK: %[[VAL_20:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_17]]) : (!fir.ref<!fir.array<100x!fir.logical<4>>>, index) -> !fir.ref<!fir.logical<4>>
146 ! CHECK: %[[VAL_23:.*]] = fir.load %[[VAL_20]] : !fir.ref<!fir.logical<4>>
147 ! CHECK: %[[VAL_24:.*]] = fir.convert %[[VAL_23]] : (!fir.logical<4>) -> i1
148 ! CHECK: %[[VAL_25:.*]] = arith.select %[[VAL_24]], %[[VAL_21]]#0, %[[VAL_22]]#0 : !fir.ref<!fir.char<1,?>>
149 ! CHECK: %[[VAL_26:.*]]:2 = hlfir.declare %[[VAL_25]] typeparams %[[VAL_6]]#1 {uniq_name = ".tmp.intrinsic_result"} : (!fir.ref<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>)
150 ! CHECK: %[[VAL_27:.*]] = hlfir.as_expr %[[VAL_26]]#0 : (!fir.boxchar<1>) -> !hlfir.expr<!fir.char<1,?>>
151 ! CHECK: hlfir.yield_element %[[VAL_27]] : !hlfir.expr<!fir.char<1,?>>
152 ! CHECK: }