1 // RUN: fir-opt %s -opt-bufferization | FileCheck %s
3 func.func @_QFPtest(%arg0: !fir.ref<!fir.array<4x7xi32>> {fir.bindc_name = "b"}, %arg1: !fir.ref<i32> {fir.bindc_name = "row"}, %arg2: !fir.ref<i32> {fir.bindc_name = "val"}) -> i32 {
4 %c1 = arith.constant 1 : index
5 %c4 = arith.constant 4 : index
6 %c7 = arith.constant 7 : index
7 %0 = fir.shape %c4, %c7 : (index, index) -> !fir.shape<2>
8 %1:2 = hlfir.declare %arg0(%0) {uniq_name = "_QFFtestEb"} : (!fir.ref<!fir.array<4x7xi32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<4x7xi32>>, !fir.ref<!fir.array<4x7xi32>>)
9 %2:2 = hlfir.declare %arg1 {uniq_name = "_QFFtestErow"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
10 %3 = fir.alloca i32 {bindc_name = "test", uniq_name = "_QFFtestEtest"}
11 %4:2 = hlfir.declare %3 {uniq_name = "_QFFtestEtest"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
12 %5:2 = hlfir.declare %arg2 {uniq_name = "_QFFtestEval"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
13 %6 = fir.load %2#0 : !fir.ref<i32>
14 %7 = fir.convert %6 : (i32) -> i64
15 %8 = fir.shape %c7 : (index) -> !fir.shape<1>
16 %9 = hlfir.designate %1#0 (%7, %c1:%c7:%c1) shape %8 : (!fir.ref<!fir.array<4x7xi32>>, i64, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<7xi32>>
17 %10 = fir.load %5#0 : !fir.ref<i32>
18 %11 = hlfir.elemental %8 unordered : (!fir.shape<1>) -> !hlfir.expr<7x!fir.logical<4>> {
20 %14 = hlfir.designate %9 (%arg3) : (!fir.box<!fir.array<7xi32>>, index) -> !fir.ref<i32>
21 %15 = fir.load %14 : !fir.ref<i32>
22 %16 = arith.cmpi sge, %15, %10 : i32
23 %17 = fir.convert %16 : (i1) -> !fir.logical<4>
24 hlfir.yield_element %17 : !fir.logical<4>
26 %12 = hlfir.count %11 : (!hlfir.expr<7x!fir.logical<4>>) -> i32
27 hlfir.assign %12 to %4#0 : i32, !fir.ref<i32>
28 hlfir.destroy %11 : !hlfir.expr<7x!fir.logical<4>>
29 %13 = fir.load %4#1 : !fir.ref<i32>
32 // CHECK-LABEL: func.func @_QFPtest(%arg0: !fir.ref<!fir.array<4x7xi32>> {fir.bindc_name = "b"}, %arg1: !fir.ref<i32> {fir.bindc_name = "row"}, %arg2: !fir.ref<i32> {fir.bindc_name = "val"}) -> i32 {
33 // CHECK-NEXT: %c1_i32 = arith.constant 1 : i32
34 // CHECK-NEXT: %c0_i32 = arith.constant 0 : i32
35 // CHECK-NEXT: %c1 = arith.constant 1 : index
36 // CHECK-NEXT: %c4 = arith.constant 4 : index
37 // CHECK-NEXT: %c7 = arith.constant 7 : index
38 // CHECK-NEXT: %[[V0:.*]] = fir.shape %c4, %c7 : (index, index) -> !fir.shape<2>
39 // CHECK-NEXT: %[[V1:.*]]:2 = hlfir.declare %arg0(%[[V0]])
40 // CHECK-NEXT: %[[V2:.*]]:2 = hlfir.declare %arg1
41 // CHECK-NEXT: %[[V3:.*]] = fir.alloca i32
42 // CHECK-NEXT: %[[V4:.*]]:2 = hlfir.declare %[[V3]]
43 // CHECK-NEXT: %[[V5:.*]]:2 = hlfir.declare %arg2
44 // CHECK-NEXT: %[[V6:.*]] = fir.load %[[V2]]#0 : !fir.ref<i32>
45 // CHECK-NEXT: %[[V7:.*]] = fir.convert %[[V6]] : (i32) -> i64
46 // CHECK-NEXT: %[[V8:.*]] = fir.shape %c7 : (index) -> !fir.shape<1>
47 // CHECK-NEXT: %[[V9:.*]] = hlfir.designate %[[V1]]#0 (%[[V7]], %c1:%c7:%c1) shape %[[V8]] : (!fir.ref<!fir.array<4x7xi32>>, i64, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<7xi32>>
48 // CHECK-NEXT: %[[V10:.*]] = fir.load %[[V5]]#0 : !fir.ref<i32>
49 // CHECK-NEXT: %[[V11:.*]] = fir.do_loop %arg3 = %c1 to %c7 step %c1 iter_args(%arg4 = %c0_i32) -> (i32) {
50 // CHECK-NEXT: %[[V13:.*]] = hlfir.designate %[[V9]] (%arg3) : (!fir.box<!fir.array<7xi32>>, index) -> !fir.ref<i32>
51 // CHECK-NEXT: %[[V14:.*]] = fir.load %[[V13]] : !fir.ref<i32>
52 // CHECK-NEXT: %[[V15:.*]] = arith.cmpi sge, %[[V14]], %[[V10]] : i32
53 // CHECK-NEXT: %[[V16:.*]] = arith.addi %arg4, %c1_i32 : i32
54 // CHECK-NEXT: %[[V17:.*]] = arith.select %[[V15]], %[[V16]], %arg4 : i32
55 // CHECK-NEXT: fir.result %[[V17]] : i32
57 // CHECK-NEXT: hlfir.assign %[[V11]] to %[[V4]]#0 : i32, !fir.ref<i32>
58 // CHECK-NEXT: %[[V12:.*]] = fir.load %[[V4]]#1 : !fir.ref<i32>
59 // CHECK-NEXT: return %[[V12]] : i32
61 func.func @_QFPtest_kind2(%arg0: !fir.ref<!fir.array<4x7xi32>> {fir.bindc_name = "b"}, %arg1: !fir.ref<i32> {fir.bindc_name = "row"}, %arg2: !fir.ref<i32> {fir.bindc_name = "val"}) -> i16 {
62 %c1 = arith.constant 1 : index
63 %c4 = arith.constant 4 : index
64 %c7 = arith.constant 7 : index
65 %0 = fir.shape %c4, %c7 : (index, index) -> !fir.shape<2>
66 %1:2 = hlfir.declare %arg0(%0) {uniq_name = "_QFFtestEb"} : (!fir.ref<!fir.array<4x7xi32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<4x7xi32>>, !fir.ref<!fir.array<4x7xi32>>)
67 %2:2 = hlfir.declare %arg1 {uniq_name = "_QFFtestErow"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
68 %3 = fir.alloca i16 {bindc_name = "test", uniq_name = "_QFFtestEtest"}
69 %4:2 = hlfir.declare %3 {uniq_name = "_QFFtestEtest"} : (!fir.ref<i16>) -> (!fir.ref<i16>, !fir.ref<i16>)
70 %5:2 = hlfir.declare %arg2 {uniq_name = "_QFFtestEval"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
71 %6 = fir.load %2#0 : !fir.ref<i32>
72 %7 = fir.convert %6 : (i32) -> i64
73 %8 = fir.shape %c7 : (index) -> !fir.shape<1>
74 %9 = hlfir.designate %1#0 (%7, %c1:%c7:%c1) shape %8 : (!fir.ref<!fir.array<4x7xi32>>, i64, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<7xi32>>
75 %10 = fir.load %5#0 : !fir.ref<i32>
76 %11 = hlfir.elemental %8 unordered : (!fir.shape<1>) -> !hlfir.expr<7x!fir.logical<4>> {
78 %14 = hlfir.designate %9 (%arg3) : (!fir.box<!fir.array<7xi32>>, index) -> !fir.ref<i32>
79 %15 = fir.load %14 : !fir.ref<i32>
80 %16 = arith.cmpi sge, %15, %10 : i32
81 %17 = fir.convert %16 : (i1) -> !fir.logical<4>
82 hlfir.yield_element %17 : !fir.logical<4>
84 %12 = hlfir.count %11 : (!hlfir.expr<7x!fir.logical<4>>) -> i16
85 hlfir.assign %12 to %4#0 : i16, !fir.ref<i16>
86 hlfir.destroy %11 : !hlfir.expr<7x!fir.logical<4>>
87 %13 = fir.load %4#1 : !fir.ref<i16>
90 // CHECK-LABEL: func.func @_QFPtest_kind2(%arg0: !fir.ref<!fir.array<4x7xi32>> {fir.bindc_name = "b"}, %arg1: !fir.ref<i32> {fir.bindc_name = "row"}, %arg2: !fir.ref<i32> {fir.bindc_name = "val"}) -> i16 {
91 // CHECK-NEXT: %c1_i16 = arith.constant 1 : i16
92 // CHECK-NEXT: %c0_i16 = arith.constant 0 : i16
93 // CHECK-NEXT: %c1 = arith.constant 1 : index
94 // CHECK-NEXT: %c4 = arith.constant 4 : index
95 // CHECK-NEXT: %c7 = arith.constant 7 : index
96 // CHECK-NEXT: %[[V0:.*]] = fir.shape %c4, %c7 : (index, index) -> !fir.shape<2>
97 // CHECK-NEXT: %[[V1:.*]]:2 = hlfir.declare %arg0(%[[V0]])
98 // CHECK-NEXT: %[[V2:.*]]:2 = hlfir.declare %arg1
99 // CHECK-NEXT: %[[V3:.*]] = fir.alloca i16
100 // CHECK-NEXT: %[[V4:.*]]:2 = hlfir.declare %[[V3]]
101 // CHECK-NEXT: %[[V5:.*]]:2 = hlfir.declare %arg2
102 // CHECK-NEXT: %[[V6:.*]] = fir.load %[[V2]]#0 : !fir.ref<i32>
103 // CHECK-NEXT: %[[V7:.*]] = fir.convert %[[V6]] : (i32) -> i64
104 // CHECK-NEXT: %[[V8:.*]] = fir.shape %c7 : (index) -> !fir.shape<1>
105 // CHECK-NEXT: %[[V9:.*]] = hlfir.designate %[[V1]]#0 (%[[V7]], %c1:%c7:%c1) shape %[[V8]] : (!fir.ref<!fir.array<4x7xi32>>, i64, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<7xi32>>
106 // CHECK-NEXT: %[[V10:.*]] = fir.load %[[V5]]#0 : !fir.ref<i32>
107 // CHECK-NEXT: %[[V11:.*]] = fir.do_loop %arg3 = %c1 to %c7 step %c1 iter_args(%arg4 = %c0_i16) -> (i16) {
108 // CHECK-NEXT: %[[V13:.*]] = hlfir.designate %[[V9]] (%arg3) : (!fir.box<!fir.array<7xi32>>, index) -> !fir.ref<i32>
109 // CHECK-NEXT: %[[V14:.*]] = fir.load %[[V13]] : !fir.ref<i32>
110 // CHECK-NEXT: %[[V15:.*]] = arith.cmpi sge, %[[V14]], %[[V10]] : i32
111 // CHECK-NEXT: %[[V16:.*]] = arith.addi %arg4, %c1_i16 : i16
112 // CHECK-NEXT: %[[V17:.*]] = arith.select %[[V15]], %[[V16]], %arg4 : i16
113 // CHECK-NEXT: fir.result %[[V17]] : i16
115 // CHECK-NEXT: hlfir.assign %[[V11]] to %[[V4]]#0 : i16, !fir.ref<i16>
116 // CHECK-NEXT: %[[V12:.*]] = fir.load %[[V4]]#1 : !fir.ref<i16>
117 // CHECK-NEXT: return %[[V12]] : i16
119 func.func @_QFPtest_dim(%arg0: !fir.ref<!fir.array<4x7xi32>> {fir.bindc_name = "b"}, %arg1: !fir.ref<i32> {fir.bindc_name = "row"}, %arg2: !fir.ref<i32> {fir.bindc_name = "val"}) -> !fir.array<7xi32> {
120 %c1_i32 = arith.constant 1 : i32
121 %c1 = arith.constant 1 : index
122 %c4 = arith.constant 4 : index
123 %c7 = arith.constant 7 : index
124 %0 = fir.shape %c4, %c7 : (index, index) -> !fir.shape<2>
125 %1:2 = hlfir.declare %arg0(%0) {uniq_name = "_QFFtestEb"} : (!fir.ref<!fir.array<4x7xi32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<4x7xi32>>, !fir.ref<!fir.array<4x7xi32>>)
126 %2:2 = hlfir.declare %arg1 {uniq_name = "_QFFtestErow"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
127 %3 = fir.alloca !fir.array<7xi32> {bindc_name = "test", uniq_name = "_QFFtestEtest"}
128 %4 = fir.shape %c7 : (index) -> !fir.shape<1>
129 %5:2 = hlfir.declare %3(%4) {uniq_name = "_QFFtestEtest"} : (!fir.ref<!fir.array<7xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<7xi32>>, !fir.ref<!fir.array<7xi32>>)
130 %6:2 = hlfir.declare %arg2 {uniq_name = "_QFFtestEval"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
131 %7 = hlfir.designate %1#0 (%c1:%c4:%c1, %c1:%c7:%c1) shape %0 : (!fir.ref<!fir.array<4x7xi32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.ref<!fir.array<4x7xi32>>
132 %8 = fir.load %6#0 : !fir.ref<i32>
133 %9 = hlfir.elemental %0 unordered : (!fir.shape<2>) -> !hlfir.expr<4x7x!fir.logical<4>> {
134 ^bb0(%arg3: index, %arg4: index):
135 %12 = hlfir.designate %7 (%arg3, %arg4) : (!fir.ref<!fir.array<4x7xi32>>, index, index) -> !fir.ref<i32>
136 %13 = fir.load %12 : !fir.ref<i32>
137 %14 = arith.cmpi sge, %13, %8 : i32
138 %15 = fir.convert %14 : (i1) -> !fir.logical<4>
139 hlfir.yield_element %15 : !fir.logical<4>
141 %10 = hlfir.count %9 dim %c1_i32 : (!hlfir.expr<4x7x!fir.logical<4>>, i32) -> !hlfir.expr<7xi32>
142 hlfir.assign %10 to %5#0 : !hlfir.expr<7xi32>, !fir.ref<!fir.array<7xi32>>
143 hlfir.destroy %10 : !hlfir.expr<7xi32>
144 hlfir.destroy %9 : !hlfir.expr<4x7x!fir.logical<4>>
145 %11 = fir.load %5#1 : !fir.ref<!fir.array<7xi32>>
146 return %11 : !fir.array<7xi32>
148 // CHECK-LABEL: func.func @_QFPtest_dim(
149 // CHECK: %{{.*}} = hlfir.count %{{.*}} dim %c1_i32
152 func.func @_QFPtest_multi(%arg0: !fir.ref<!fir.array<4x7x2xi32>> {fir.bindc_name = "b"}, %arg1: !fir.ref<i32> {fir.bindc_name = "row"}, %arg2: !fir.ref<i32> {fir.bindc_name = "val"}) -> i32 {
153 %c1 = arith.constant 1 : index
154 %c4 = arith.constant 4 : index
155 %c7 = arith.constant 7 : index
156 %c2 = arith.constant 2 : index
157 %0 = fir.shape %c4, %c7, %c2 : (index, index, index) -> !fir.shape<3>
158 %1:2 = hlfir.declare %arg0(%0) {uniq_name = "_QFFtestEb"} : (!fir.ref<!fir.array<4x7x2xi32>>, !fir.shape<3>) -> (!fir.ref<!fir.array<4x7x2xi32>>, !fir.ref<!fir.array<4x7x2xi32>>)
159 %2:2 = hlfir.declare %arg1 {uniq_name = "_QFFtestErow"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
160 %3 = fir.alloca i32 {bindc_name = "test", uniq_name = "_QFFtestEtest"}
161 %4:2 = hlfir.declare %3 {uniq_name = "_QFFtestEtest"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
162 %5:2 = hlfir.declare %arg2 {uniq_name = "_QFFtestEval"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
163 %6 = hlfir.designate %1#0 (%c1:%c4:%c1, %c1:%c7:%c1, %c1:%c2:%c1) shape %0 : (!fir.ref<!fir.array<4x7x2xi32>>, index, index, index, index, index, index, index, index, index, !fir.shape<3>) -> !fir.ref<!fir.array<4x7x2xi32>>
164 %7 = fir.load %5#0 : !fir.ref<i32>
165 %8 = hlfir.elemental %0 unordered : (!fir.shape<3>) -> !hlfir.expr<4x7x2x!fir.logical<4>> {
166 ^bb0(%arg3: index, %arg4: index, %arg5: index):
167 %11 = hlfir.designate %6 (%arg3, %arg4, %arg5) : (!fir.ref<!fir.array<4x7x2xi32>>, index, index, index) -> !fir.ref<i32>
168 %12 = fir.load %11 : !fir.ref<i32>
169 %13 = arith.cmpi sge, %12, %7 : i32
170 %14 = fir.convert %13 : (i1) -> !fir.logical<4>
171 hlfir.yield_element %14 : !fir.logical<4>
173 %9 = hlfir.count %8 : (!hlfir.expr<4x7x2x!fir.logical<4>>) -> i32
174 hlfir.assign %9 to %4#0 : i32, !fir.ref<i32>
175 hlfir.destroy %8 : !hlfir.expr<4x7x2x!fir.logical<4>>
176 %10 = fir.load %4#1 : !fir.ref<i32>
179 // CHECK-LABEL: func.func @_QFPtest_multi(%arg0: !fir.ref<!fir.array<4x7x2xi32>> {fir.bindc_name = "b"}, %arg1: !fir.ref<i32> {fir.bindc_name = "row"}, %arg2: !fir.ref<i32> {fir.bindc_name = "val"}) -> i32 {
180 // CHECK-NEXT: %c1_i32 = arith.constant 1 : i32
181 // CHECK-NEXT: %c0_i32 = arith.constant 0 : i32
182 // CHECK-NEXT: %c1 = arith.constant 1 : index
183 // CHECK-NEXT: %c4 = arith.constant 4 : index
184 // CHECK-NEXT: %c7 = arith.constant 7 : index
185 // CHECK-NEXT: %c2 = arith.constant 2 : index
186 // CHECK-NEXT: %[[V0:.*]] = fir.shape %c4, %c7, %c2 : (index, index, index) -> !fir.shape<3>
187 // CHECK-NEXT: %[[V1:.*]]:2 = hlfir.declare %arg0(%[[V0]]) {uniq_name = "_QFFtestEb"} : (!fir.ref<!fir.array<4x7x2xi32>>, !fir.shape<3>) -> (!fir.ref<!fir.array<4x7x2xi32>>, !fir.ref<!fir.array<4x7x2xi32>>)
188 // CHECK-NEXT: %[[V2:.*]]:2 = hlfir.declare %arg1 {uniq_name = "_QFFtestErow"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
189 // CHECK-NEXT: %[[V3:.*]] = fir.alloca i32 {bindc_name = "test", uniq_name = "_QFFtestEtest"}
190 // CHECK-NEXT: %[[V4:.*]]:2 = hlfir.declare %[[V3]] {uniq_name = "_QFFtestEtest"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
191 // CHECK-NEXT: %[[V5:.*]]:2 = hlfir.declare %arg2 {uniq_name = "_QFFtestEval"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
192 // CHECK-NEXT: %[[V6:.*]] = hlfir.designate %[[V1]]#0 (%c1:%c4:%c1, %c1:%c7:%c1, %c1:%c2:%c1) shape %[[V0]] : (!fir.ref<!fir.array<4x7x2xi32>>, index, index, index, index, index, index, index, index, index, !fir.shape<3>) -> !fir.ref<!fir.array<4x7x2xi32>>
193 // CHECK-NEXT: %[[V7:.*]] = fir.load %[[V5]]#0 : !fir.ref<i32>
194 // CHECK-NEXT: %[[V8:.*]] = fir.do_loop %arg3 = %c1 to %c2 step %c1 iter_args(%arg4 = %c0_i32) -> (i32) {
195 // CHECK-NEXT: %[[V10:.*]] = fir.do_loop %arg5 = %c1 to %c7 step %c1 iter_args(%arg6 = %arg4) -> (i32) {
196 // CHECK-NEXT: %[[V11:.*]] = fir.do_loop %arg7 = %c1 to %c4 step %c1 iter_args(%arg8 = %arg6) -> (i32) {
197 // CHECK-NEXT: %[[V12:.*]] = hlfir.designate %[[V6]] (%arg7, %arg5, %arg3) : (!fir.ref<!fir.array<4x7x2xi32>>, index, index, index) -> !fir.ref<i32>
198 // CHECK-NEXT: %[[V13:.*]] = fir.load %[[V12]] : !fir.ref<i32>
199 // CHECK-NEXT: %[[V14:.*]] = arith.cmpi sge, %[[V13]], %[[V7]] : i32
200 // CHECK-NEXT: %[[V15:.*]] = arith.addi %arg8, %c1_i32 : i32
201 // CHECK-NEXT: %[[V16:.*]] = arith.select %[[V14]], %[[V15]], %arg8 : i32
202 // CHECK-NEXT: fir.result %[[V16]] : i32
204 // CHECK-NEXT: fir.result %[[V11]] : i32
206 // CHECK-NEXT: fir.result %[[V10]] : i32
208 // CHECK-NEXT: hlfir.assign %[[V8]] to %[[V4]]#0 : i32, !fir.ref<i32>
209 // CHECK-NEXT: %[[V9:.*]] = fir.load %[[V4]]#1 : !fir.ref<i32>
210 // CHECK-NEXT: return %[[V9]] : i32
216 func.func @_QFPtest_rec_sum(%arg0: !fir.ref<!fir.array<4x7xi32>> {fir.bindc_name = "b"}, %arg1: !fir.ref<i32> {fir.bindc_name = "row"}, %arg2: !fir.ref<i32> {fir.bindc_name = "val"}) -> i32 {
217 %c1 = arith.constant 1 : index
218 %c4 = arith.constant 4 : index
219 %c7 = arith.constant 7 : index
220 %0 = fir.shape %c4, %c7 : (index, index) -> !fir.shape<2>
221 %1:2 = hlfir.declare %arg0(%0) {uniq_name = "_QFFtestEb"} : (!fir.ref<!fir.array<4x7xi32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<4x7xi32>>, !fir.ref<!fir.array<4x7xi32>>)
222 %2:2 = hlfir.declare %arg1 {uniq_name = "_QFFtestErow"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
223 %3 = fir.alloca i32 {bindc_name = "test", uniq_name = "_QFFtestEtest"}
224 %4:2 = hlfir.declare %3 {uniq_name = "_QFFtestEtest"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
225 %5:2 = hlfir.declare %arg2 {uniq_name = "_QFFtestEval"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
226 %6 = fir.load %2#0 : !fir.ref<i32>
227 %7 = fir.convert %6 : (i32) -> i64
228 %8 = fir.shape %c7 : (index) -> !fir.shape<1>
229 %9 = hlfir.designate %1#0 (%7, %c1:%c7:%c1) shape %8 : (!fir.ref<!fir.array<4x7xi32>>, i64, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<7xi32>>
230 %10 = fir.load %5#0 : !fir.ref<i32>
231 %11 = hlfir.elemental %8 unordered : (!fir.shape<1>) -> !hlfir.expr<7xi32> {
233 %15 = hlfir.designate %9 (%arg3) : (!fir.box<!fir.array<7xi32>>, index) -> !fir.ref<i32>
234 %16 = fir.load %15 : !fir.ref<i32>
235 hlfir.yield_element %16 : i32
237 %12 = hlfir.elemental %8 unordered : (!fir.shape<1>) -> !hlfir.expr<7x!fir.logical<4>> {
239 %15 = hlfir.sum %11 : (!hlfir.expr<7xi32>) -> i32
240 %16 = arith.cmpi sge, %15, %10 : i32
241 %17 = fir.convert %16 : (i1) -> !fir.logical<4>
242 hlfir.yield_element %17 : !fir.logical<4>
244 %13 = hlfir.count %12 : (!hlfir.expr<7x!fir.logical<4>>) -> i32
245 hlfir.assign %13 to %4#0 : i32, !fir.ref<i32>
246 hlfir.destroy %12 : !hlfir.expr<7x!fir.logical<4>>
247 hlfir.destroy %11 : !hlfir.expr<7xi32>
248 %14 = fir.load %4#1 : !fir.ref<i32>
251 // CHECK-LABEL: func.func @_QFPtest_rec_sum(%arg0: !fir.ref<!fir.array<4x7xi32>> {fir.bindc_name = "b"}, %arg1: !fir.ref<i32> {fir.bindc_name = "row"}, %arg2: !fir.ref<i32> {fir.bindc_name = "val"}) -> i32 {
252 // CHECK: %[[V12:.*]] = fir.do_loop %arg3 = %c1 to %c7 step %c1 iter_args(%arg4 = %c0_i32) -> (i32) {
253 // CHECK: %[[V14:.*]] = hlfir.sum %[[V11]] : (!hlfir.expr<7xi32>) -> i32
254 // CHECK: %[[V15:.*]] = arith.cmpi sge, %[[V14]], %[[V10]] : i32
255 // CHECK: %[[V16:.*]] = arith.addi %arg4, %c1_i32 : i32
256 // CHECK: %[[V17:.*]] = arith.select %[[V15]], %[[V16]], %arg4 : i32
257 // CHECK: fir.result %[[V17]] : i32
263 func.func @_QFPtest_rec_count(%arg0: !fir.ref<!fir.array<4x7xi32>> {fir.bindc_name = "b"}, %arg1: !fir.ref<i32> {fir.bindc_name = "row"}, %arg2: !fir.ref<i32> {fir.bindc_name = "val"}) -> i32 {
264 %c1 = arith.constant 1 : index
265 %c4 = arith.constant 4 : index
266 %c7 = arith.constant 7 : index
267 %0 = fir.shape %c4, %c7 : (index, index) -> !fir.shape<2>
268 %1:2 = hlfir.declare %arg0(%0) {uniq_name = "_QFFtestEb"} : (!fir.ref<!fir.array<4x7xi32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<4x7xi32>>, !fir.ref<!fir.array<4x7xi32>>)
269 %2:2 = hlfir.declare %arg1 {uniq_name = "_QFFtestErow"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
270 %3 = fir.alloca i32 {bindc_name = "test", uniq_name = "_QFFtestEtest"}
271 %4:2 = hlfir.declare %3 {uniq_name = "_QFFtestEtest"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
272 %5:2 = hlfir.declare %arg2 {uniq_name = "_QFFtestEval"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
273 %6 = fir.load %2#0 : !fir.ref<i32>
274 %7 = fir.convert %6 : (i32) -> i64
275 %8 = fir.shape %c7 : (index) -> !fir.shape<1>
276 %9 = hlfir.designate %1#0 (%7, %c1:%c7:%c1) shape %8 : (!fir.ref<!fir.array<4x7xi32>>, i64, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<7xi32>>
277 %10 = fir.load %5#0 : !fir.ref<i32>
278 %11 = hlfir.elemental %8 unordered : (!fir.shape<1>) -> !hlfir.expr<7x!fir.logical<4>> {
280 %15 = hlfir.designate %9 (%arg3) : (!fir.box<!fir.array<7xi32>>, index) -> !fir.ref<i32>
281 %16 = fir.load %15 : !fir.ref<i32>
282 %17 = arith.cmpi sge, %16, %10 : i32
283 %18 = fir.convert %17 : (i1) -> !fir.logical<4>
284 hlfir.yield_element %18 : !fir.logical<4>
286 %12 = hlfir.elemental %8 unordered : (!fir.shape<1>) -> !hlfir.expr<7x!fir.logical<4>> {
288 %15 = hlfir.count %11 : (!hlfir.expr<7x!fir.logical<4>>) -> i32
289 %16 = arith.cmpi sge, %15, %10 : i32
290 %17 = fir.convert %16 : (i1) -> !fir.logical<4>
291 hlfir.yield_element %17 : !fir.logical<4>
293 %13 = hlfir.count %12 : (!hlfir.expr<7x!fir.logical<4>>) -> i32
294 hlfir.assign %13 to %4#0 : i32, !fir.ref<i32>
295 hlfir.destroy %12 : !hlfir.expr<7x!fir.logical<4>>
296 hlfir.destroy %11 : !hlfir.expr<7x!fir.logical<4>>
297 %14 = fir.load %4#1 : !fir.ref<i32>
300 // CHECK-LABEL: func.func @_QFPtest_rec_count(%arg0: !fir.ref<!fir.array<4x7xi32>> {fir.bindc_name = "b"}, %arg1: !fir.ref<i32> {fir.bindc_name = "row"}, %arg2: !fir.ref<i32> {fir.bindc_name = "val"}) -> i32 {
301 // CHECK: %[[V11:.*]] = fir.do_loop %arg3 = %c1 to %c7 step %c1 iter_args(%arg4 = %c0_i32) -> (i32) {
302 // CHECK: %[[V13:.*]] = fir.do_loop %arg5 = %c1 to %c7 step %c1 iter_args(%arg6 = %c0_i32) -> (i32) {
303 // CHECK: %[[V17:.*]] = hlfir.designate %[[V9]] (%arg5) : (!fir.box<!fir.array<7xi32>>, index) -> !fir.ref<i32>
304 // CHECK: %[[V18:.*]] = fir.load %[[V17]] : !fir.ref<i32>
305 // CHECK: %[[V19:.*]] = arith.cmpi sge, %[[V18]], %[[V10]] : i32
306 // CHECK: %[[V20:.*]] = arith.addi %arg6, %c1_i32 : i32
307 // CHECK: %[[V21:.*]] = arith.select %[[V19]], %[[V20]], %arg6 : i32
308 // CHECK: fir.result %[[V21]] : i32
310 // CHECK: %[[V14:.*]] = arith.cmpi sge, %[[V13]], %[[V10]] : i32
311 // CHECK: %[[V15:.*]] = arith.addi %arg4, %c1_i32 : i32
312 // CHECK: %[[V16:.*]] = arith.select %[[V14]], %[[V15]], %arg4 : i32
313 // CHECK: fir.result %[[V16]] : i32