[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Lower / HLFIR / elemental-array-ops.f90
blob9a240438d110c49fed9761fe928931cfe4483940
1 ! Test lowering of elemental intrinsic operations with array arguments to HLFIR
2 ! RUN: bbc -emit-fir -hlfir -o - %s 2>&1 | FileCheck %s
4 subroutine binary(x, y)
5 integer :: x(100), y(100)
6 x = x+y
7 end subroutine
8 ! CHECK-LABEL: func.func @_QPbinary(
9 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %{{.*}}(%[[VAL_3:[^)]*]]) {{.*}}x
10 ! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %{{.*}}(%[[VAL_6:[^)]*]]) {{.*}}y
11 ! CHECK: %[[VAL_8:.*]] = hlfir.elemental %[[VAL_3]] : (!fir.shape<1>) -> !hlfir.expr<100xi32> {
12 ! CHECK: ^bb0(%[[VAL_9:.*]]: index):
13 ! CHECK: %[[VAL_10:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_9]]) : (!fir.ref<!fir.array<100xi32>>, index) -> !fir.ref<i32>
14 ! CHECK: %[[VAL_11:.*]] = hlfir.designate %[[VAL_7]]#0 (%[[VAL_9]]) : (!fir.ref<!fir.array<100xi32>>, index) -> !fir.ref<i32>
15 ! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_10]] : !fir.ref<i32>
16 ! CHECK: %[[VAL_13:.*]] = fir.load %[[VAL_11]] : !fir.ref<i32>
17 ! CHECK: %[[VAL_14:.*]] = arith.addi %[[VAL_12]], %[[VAL_13]] : i32
18 ! CHECK: hlfir.yield_element %[[VAL_14]] : i32
19 ! CHECK: }
20 ! CHECK: hlfir.assign
21 ! CHECK: hlfir.destroy %[[VAL_8]]
23 subroutine binary_with_scalar_and_array(x, y)
24 integer :: x(100), y
25 x = x+y
26 end subroutine
27 ! CHECK-LABEL: func.func @_QPbinary_with_scalar_and_array(
28 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %{{.*}}(%[[VAL_3:[^)]*]]) {{.*}}x
29 ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %{{.*}} {{.*}}y
30 ! CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i32>
31 ! CHECK: %[[VAL_7:.*]] = hlfir.elemental %[[VAL_3]] : (!fir.shape<1>) -> !hlfir.expr<100xi32> {
32 ! CHECK: ^bb0(%[[VAL_8:.*]]: index):
33 ! CHECK: %[[VAL_9:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_8]]) : (!fir.ref<!fir.array<100xi32>>, index) -> !fir.ref<i32>
34 ! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_9]] : !fir.ref<i32>
35 ! CHECK: %[[VAL_11:.*]] = arith.addi %[[VAL_10]], %[[VAL_6]] : i32
36 ! CHECK: hlfir.yield_element %[[VAL_11]] : i32
37 ! CHECK: }
38 ! CHECK: hlfir.assign
39 ! CHECK: hlfir.destroy %[[VAL_7]]
41 subroutine char_binary(x, y)
42 character(*) :: x(100), y(100)
43 call test_char(x//y)
44 end subroutine
45 ! CHECK-LABEL: func.func @_QPchar_binary(
46 ! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %{{.*}}(%[[VAL_5:.*]]) typeparams %[[VAL_2:.*]]#1 {{.*}}x
47 ! CHECK: %[[VAL_11:.*]]:2 = hlfir.declare %{{.*}}(%[[VAL_10:.*]]) typeparams %[[VAL_7:.*]]#1 {{.*}}y
48 ! CHECK: %[[VAL_12:.*]] = arith.addi %[[VAL_2]]#1, %[[VAL_7]]#1 : index
49 ! CHECK: %[[VAL_13:.*]] = hlfir.elemental %[[VAL_5]] typeparams %[[VAL_12]] : (!fir.shape<1>, index) -> !hlfir.expr<100x!fir.char<1,?>> {
50 ! CHECK: ^bb0(%[[VAL_14:.*]]: index):
51 ! 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>
52 ! CHECK: %[[VAL_16:.*]] = hlfir.designate %[[VAL_11]]#0 (%[[VAL_14]]) typeparams %[[VAL_7]]#1 : (!fir.box<!fir.array<100x!fir.char<1,?>>>, index, index) -> !fir.boxchar<1>
53 ! CHECK: %[[VAL_17:.*]] = hlfir.concat %[[VAL_15]], %[[VAL_16]] len %[[VAL_12]] : (!fir.boxchar<1>, !fir.boxchar<1>, index) -> !hlfir.expr<!fir.char<1,?>>
54 ! CHECK: hlfir.yield_element %[[VAL_17]] : !hlfir.expr<!fir.char<1,?>>
55 ! CHECK: }
56 ! CHECK: fir.call
57 ! CHECK: hlfir.destroy %[[VAL_13]]
59 subroutine unary(x, n)
60 integer :: n
61 logical :: x(n)
62 x = .not.x
63 end subroutine
64 ! CHECK-LABEL: func.func @_QPunary(
65 ! CHECK: %[[VAL_10:.*]]:2 = hlfir.declare %{{.*}}(%[[VAL_9:[^)]*]]) {{.*}}x
66 ! CHECK: %[[VAL_11:.*]] = hlfir.elemental %[[VAL_9]] : (!fir.shape<1>) -> !hlfir.expr<?x!fir.logical<4>> {
67 ! CHECK: ^bb0(%[[VAL_12:.*]]: index):
68 ! CHECK: %[[VAL_13:.*]] = hlfir.designate %[[VAL_10]]#0 (%[[VAL_12]]) : (!fir.box<!fir.array<?x!fir.logical<4>>>, index) -> !fir.ref<!fir.logical<4>>
69 ! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_13]] : !fir.ref<!fir.logical<4>>
70 ! CHECK: %[[VAL_15:.*]] = arith.constant true
71 ! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_14]] : (!fir.logical<4>) -> i1
72 ! CHECK: %[[VAL_17:.*]] = arith.xori %[[VAL_16]], %[[VAL_15]] : i1
73 ! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (i1) -> !fir.logical<4>
74 ! CHECK: hlfir.yield_element %[[VAL_18]] : !fir.logical<4>
75 ! CHECK: }
76 ! CHECK: hlfir.assign
77 ! CHECK: hlfir.destroy %[[VAL_11]]
79 subroutine char_unary(x)
80 character(10) :: x(20)
81 call test_char_2((x))
82 end subroutine
83 ! CHECK-LABEL: func.func @_QPchar_unary(
84 ! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %{{.*}}(%[[VAL_5:.*]]) typeparams %[[VAL_2:[^ ]*]] {{.*}}x
85 ! CHECK: %[[VAL_7:.*]] = hlfir.elemental %[[VAL_5]] typeparams %[[VAL_2]] : (!fir.shape<1>, index) -> !hlfir.expr<20x!fir.char<1,?>> {
86 ! CHECK: ^bb0(%[[VAL_8:.*]]: index):
87 ! CHECK: %[[VAL_9:.*]] = hlfir.designate %[[VAL_6]]#0 (%[[VAL_8]]) typeparams %[[VAL_2]] : (!fir.ref<!fir.array<20x!fir.char<1,10>>>, index, index) -> !fir.ref<!fir.char<1,10>>
88 ! CHECK: %[[VAL_10:.*]] = hlfir.as_expr %[[VAL_9]] : (!fir.ref<!fir.char<1,10>>) -> !hlfir.expr<!fir.char<1,10>>
89 ! CHECK: hlfir.yield_element %[[VAL_10]] : !hlfir.expr<!fir.char<1,10>>
90 ! CHECK: }
91 ! CHECK: fir.call
92 ! CHECK: hlfir.destroy %[[VAL_7]]
94 subroutine chained_elemental(x, y, z)
95 integer :: x(100), y(100), z(100)
96 x = x+y+z
97 end subroutine
98 ! CHECK-LABEL: func.func @_QPchained_elemental(
99 ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %{{.*}}(%[[VAL_4:[^)]*]]) {{.*}}x
100 ! CHECK: %[[VAL_8:.*]]:2 = hlfir.declare %{{.*}}(%[[VAL_7:[^)]*]]) {{.*}}y
101 ! CHECK: %[[VAL_11:.*]]:2 = hlfir.declare %{{.*}}(%[[VAL_10:[^)]*]]) {{.*}}z
102 ! CHECK: %[[VAL_12:.*]] = hlfir.elemental %[[VAL_4]] : (!fir.shape<1>) -> !hlfir.expr<100xi32> {
103 ! CHECK: ^bb0(%[[VAL_13:.*]]: index):
104 ! CHECK: %[[VAL_14:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_13]]) : (!fir.ref<!fir.array<100xi32>>, index) -> !fir.ref<i32>
105 ! CHECK: %[[VAL_15:.*]] = hlfir.designate %[[VAL_8]]#0 (%[[VAL_13]]) : (!fir.ref<!fir.array<100xi32>>, index) -> !fir.ref<i32>
106 ! CHECK: %[[VAL_16:.*]] = fir.load %[[VAL_14]] : !fir.ref<i32>
107 ! CHECK: %[[VAL_17:.*]] = fir.load %[[VAL_15]] : !fir.ref<i32>
108 ! CHECK: %[[VAL_18:.*]] = arith.addi %[[VAL_16]], %[[VAL_17]] : i32
109 ! CHECK: hlfir.yield_element %[[VAL_18]] : i32
110 ! CHECK: }
111 ! CHECK: %[[VAL_19:.*]] = hlfir.elemental %[[VAL_4]] : (!fir.shape<1>) -> !hlfir.expr<100xi32> {
112 ! CHECK: ^bb0(%[[VAL_20:.*]]: index):
113 ! CHECK: %[[VAL_21:.*]] = hlfir.apply %[[VAL_22:.*]], %[[VAL_20]] : (!hlfir.expr<100xi32>, index) -> i32
114 ! CHECK: %[[VAL_23:.*]] = hlfir.designate %[[VAL_11]]#0 (%[[VAL_20]]) : (!fir.ref<!fir.array<100xi32>>, index) -> !fir.ref<i32>
115 ! CHECK: %[[VAL_24:.*]] = fir.load %[[VAL_23]] : !fir.ref<i32>
116 ! CHECK: %[[VAL_25:.*]] = arith.addi %[[VAL_21]], %[[VAL_24]] : i32
117 ! CHECK: hlfir.yield_element %[[VAL_25]] : i32
118 ! CHECK: }
119 ! CHECK: hlfir.assign
120 ! CHECK: hlfir.destroy %[[VAL_19]]
121 ! CHECK: hlfir.destroy %[[VAL_12]]
123 subroutine lower_bounds(x)
124 integer :: x(2:101)
125 call test((x))
126 end subroutine
127 ! CHECK-LABEL: func.func @_QPlower_bounds(
128 ! CHECK: %[[VAL_1:.*]] = arith.constant 2 : index
129 ! CHECK: %[[VAL_2:.*]] = arith.constant 100 : index
130 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %{{.*}}(%[[VAL_3:[^)]*]]) {{.*}}x
131 ! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1>
132 ! CHECK: %[[VAL_6:.*]] = hlfir.elemental %[[VAL_5]] : (!fir.shape<1>) -> !hlfir.expr<100xi32> {
133 ! CHECK: ^bb0(%[[VAL_7:.*]]: index):
134 ! CHECK: %[[VAL_8:.*]] = arith.constant 1 : index
135 ! CHECK: %[[VAL_9:.*]] = arith.subi %[[VAL_1]], %[[VAL_8]] : index
136 ! CHECK: %[[VAL_10:.*]] = arith.addi %[[VAL_7]], %[[VAL_9]] : index
137 ! CHECK: %[[VAL_11:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_10]]) : (!fir.box<!fir.array<100xi32>>, index) -> !fir.ref<i32>
138 ! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_11]] : !fir.ref<i32>
139 ! CHECK: %[[VAL_13:.*]] = hlfir.no_reassoc %[[VAL_12]] : i32
140 ! CHECK: hlfir.yield_element %[[VAL_13]] : i32
141 ! CHECK: }
142 ! CHECK: fir.call
143 ! CHECK: hlfir.destroy %[[VAL_6]]