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"}) -> !fir.logical<4> {
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 !fir.logical<4> {bindc_name = "test", uniq_name = "_QFFtestEtest"}
11 %4:2 = hlfir.declare %3 {uniq_name = "_QFFtestEtest"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>)
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.all %11 : (!hlfir.expr<7x!fir.logical<4>>) -> !fir.logical<4>
27 hlfir.assign %12 to %4#0 : !fir.logical<4>, !fir.ref<!fir.logical<4>>
28 hlfir.destroy %11 : !hlfir.expr<7x!fir.logical<4>>
29 %13 = fir.load %4#1 : !fir.ref<!fir.logical<4>>
30 return %13 : !fir.logical<4>
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"}) -> !fir.logical<4> {
33 // CHECK-NEXT: %true = arith.constant true
34 // CHECK-NEXT: %c1 = arith.constant 1 : index
35 // CHECK-NEXT: %c4 = arith.constant 4 : index
36 // CHECK-NEXT: %c7 = arith.constant 7 : index
37 // CHECK-NEXT: %[[V0:.*]] = fir.shape %c4, %c7 : (index, index) -> !fir.shape<2>
38 // CHECK-NEXT: %[[V1:.*]]:2 = hlfir.declare %arg0(%[[V0]])
39 // CHECK-NEXT: %[[V2:.*]]:2 = hlfir.declare %arg1
40 // CHECK-NEXT: %[[V3:.*]] = fir.alloca !fir.logical<4>
41 // CHECK-NEXT: %[[V4:.*]]:2 = hlfir.declare %[[V3]]
42 // CHECK-NEXT: %[[V5:.*]]:2 = hlfir.declare %arg2
43 // CHECK-NEXT: %[[V6:.*]] = fir.load %[[V2]]#0 : !fir.ref<i32>
44 // CHECK-NEXT: %[[V7:.*]] = fir.convert %[[V6]] : (i32) -> i64
45 // CHECK-NEXT: %[[V8:.*]] = fir.shape %c7 : (index) -> !fir.shape<1>
46 // 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>>
47 // CHECK-NEXT: %[[V10:.*]] = fir.load %[[V5]]#0 : !fir.ref<i32>
48 // CHECK-NEXT: %[[V11:.*]] = fir.do_loop %arg3 = %c1 to %c7 step %c1 iter_args(%arg4 = %true) -> (i1) {
49 // CHECK-NEXT: %[[V14:.*]] = hlfir.designate %[[V9]] (%arg3) : (!fir.box<!fir.array<7xi32>>, index) -> !fir.ref<i32>
50 // CHECK-NEXT: %[[V15:.*]] = fir.load %[[V14]] : !fir.ref<i32>
51 // CHECK-NEXT: %[[V16:.*]] = arith.cmpi sge, %[[V15]], %[[V10]] : i32
52 // CHECK-NEXT: %[[V17:.*]] = arith.andi %arg4, %[[V16]] : i1
53 // CHECK-NEXT: fir.result %[[V17]] : i1
55 // CHECK-NEXT: %[[V12:.*]] = fir.convert %[[V11]] : (i1) -> !fir.logical<4>
56 // CHECK-NEXT: hlfir.assign %[[V12]] to %[[V4]]#0 : !fir.logical<4>, !fir.ref<!fir.logical<4>>
57 // CHECK-NEXT: %[[V13:.*]] = fir.load %[[V4]]#1 : !fir.ref<!fir.logical<4>>
58 // CHECK-NEXT: return %[[V13]] : !fir.logical<4>
61 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<4x!fir.logical<4>> {
62 %c2_i32 = arith.constant 2 : i32
63 %c1 = arith.constant 1 : index
64 %c4 = arith.constant 4 : index
65 %c7 = arith.constant 7 : index
66 %0 = fir.shape %c4, %c7 : (index, index) -> !fir.shape<2>
67 %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>>)
68 %2:2 = hlfir.declare %arg1 {uniq_name = "_QFFtestErow"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
69 %3 = fir.alloca !fir.array<4x!fir.logical<4>> {bindc_name = "test", uniq_name = "_QFFtestEtest"}
70 %4 = fir.shape %c4 : (index) -> !fir.shape<1>
71 %5:2 = hlfir.declare %3(%4) {uniq_name = "_QFFtestEtest"} : (!fir.ref<!fir.array<4x!fir.logical<4>>>, !fir.shape<1>) -> (!fir.ref<!fir.array<4x!fir.logical<4>>>, !fir.ref<!fir.array<4x!fir.logical<4>>>)
72 %6:2 = hlfir.declare %arg2 {uniq_name = "_QFFtestEval"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
73 %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>>
74 %8 = fir.load %6#0 : !fir.ref<i32>
75 %9 = hlfir.elemental %0 unordered : (!fir.shape<2>) -> !hlfir.expr<4x7x!fir.logical<4>> {
76 ^bb0(%arg3: index, %arg4: index):
77 %12 = hlfir.designate %7 (%arg3, %arg4) : (!fir.ref<!fir.array<4x7xi32>>, index, index) -> !fir.ref<i32>
78 %13 = fir.load %12 : !fir.ref<i32>
79 %14 = arith.cmpi sge, %13, %8 : i32
80 %15 = fir.convert %14 : (i1) -> !fir.logical<4>
81 hlfir.yield_element %15 : !fir.logical<4>
83 %10 = hlfir.all %9 dim %c2_i32 : (!hlfir.expr<4x7x!fir.logical<4>>, i32) -> !hlfir.expr<4x!fir.logical<4>>
84 hlfir.assign %10 to %5#0 : !hlfir.expr<4x!fir.logical<4>>, !fir.ref<!fir.array<4x!fir.logical<4>>>
85 hlfir.destroy %10 : !hlfir.expr<4x!fir.logical<4>>
86 hlfir.destroy %9 : !hlfir.expr<4x7x!fir.logical<4>>
87 %11 = fir.load %5#1 : !fir.ref<!fir.array<4x!fir.logical<4>>>
88 return %11 : !fir.array<4x!fir.logical<4>>
90 // CHECK-LABEL: func.func @_QFPtest_dim(
91 // CHECK: %10 = hlfir.all %9 dim %c2_i32