1 // Test hlfir.all operation lowering to fir runtime call
2 // RUN: fir-opt %s -lower-hlfir-intrinsics | FileCheck %s
4 func.func @_QPall1(%arg0: !fir.box<!fir.array<?x!fir.logical<4>>> {fir.bindc_name = "a"}, %arg1: !fir.ref<!fir.logical<4>> {fir.bindc_name = "s"}) {
5 %0:2 = hlfir.declare %arg0 {uniq_name = "_QFall1Ea"} : (!fir.box<!fir.array<?x!fir.logical<4>>>) -> (!fir.box<!fir.array<?x!fir.logical<4>>>, !fir.box<!fir.array<?x!fir.logical<4>>>)
6 %1:2 = hlfir.declare %arg1 {uniq_name = "_QFall1Es"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>)
7 %2 = hlfir.all %0#0 : (!fir.box<!fir.array<?x!fir.logical<4>>>) -> !fir.logical<4>
8 hlfir.assign %2 to %1#0 : !fir.logical<4>, !fir.ref<!fir.logical<4>>
11 // CHECK-LABEL: func.func @_QPall1(
12 // CHECK: %[[ARG0:.*]]: !fir.box<!fir.array<?x!fir.logical<4>>> {fir.bindc_name = "a"}
13 // CHECK: %[[ARG1:.*]]: !fir.ref<!fir.logical<4>>
14 // CHECK-DAG: %[[MASK:.*]]:2 = hlfir.declare %[[ARG0]]
15 // CHECK-DAG: %[[RES:.*]]:2 = hlfir.declare %[[ARG1]]
16 // CHECK-DAG: %[[MASK_ARG:.*]] = fir.convert %[[MASK]]#1 : (!fir.box<!fir.array<?x!fir.logical<4>>>) -> !fir.box<none>
17 // CHECK: %[[RET_ARG:.*]] = fir.call @_FortranAAll(%[[MASK_ARG]], %[[LOC_STR:.*]], %[[LOC_N:.*]], %[[C1:.*]]) : (!fir.box<none>, !fir.ref<i8>, i32, i32) -> i1
18 // CHECK-NEXT: %[[RET:.*]] = fir.convert %[[RET_ARG]] : (i1) -> !fir.logical<4>
19 // CHECK-NEXT: hlfir.assign %[[RET]] to %[[RES]]#0 : !fir.logical<4>, !fir.ref<!fir.logical<4>>
23 func.func @_QPall2(%arg0: !fir.box<!fir.array<?x?x!fir.logical<4>>> {fir.bindc_name = "a"}, %arg1: !fir.box<!fir.array<?x!fir.logical<4>>> {fir.bindc_name = "s"}, %arg2: !fir.ref<i32> {fir.bindc_name = "d"}) {
24 %0:2 = hlfir.declare %arg0 {uniq_name = "_QFall2Ea"} : (!fir.box<!fir.array<?x?x!fir.logical<4>>>) -> (!fir.box<!fir.array<?x?x!fir.logical<4>>>, !fir.box<!fir.array<?x?x!fir.logical<4>>>)
25 %1:2 = hlfir.declare %arg2 {uniq_name = "_QFall2Ed"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
26 %2:2 = hlfir.declare %arg1 {uniq_name = "_QFall2Es"} : (!fir.box<!fir.array<?x!fir.logical<4>>>) -> (!fir.box<!fir.array<?x!fir.logical<4>>>, !fir.box<!fir.array<?x!fir.logical<4>>>)
27 %3 = fir.load %1#0 : !fir.ref<i32>
28 %4 = hlfir.all %0#0 dim %3 : (!fir.box<!fir.array<?x?x!fir.logical<4>>>, i32) -> !hlfir.expr<?x!fir.logical<4>>
29 hlfir.assign %4 to %2#0 : !hlfir.expr<?x!fir.logical<4>>, !fir.box<!fir.array<?x!fir.logical<4>>>
30 hlfir.destroy %4 : !hlfir.expr<?x!fir.logical<4>>
33 // CHECK-LABEL: func.func @_QPall2(
34 // CHECK: %[[ARG0:.*]]: !fir.box<!fir.array<?x?x!fir.logical<4>>>
35 // CHECK: %[[ARG1:.*]]: !fir.box<!fir.array<?x!fir.logical<4>>>
36 // CHECK: %[[ARG2:.*]]: !fir.ref<i32>
37 // CHECK-DAG: %[[TRUE:.*]] = arith.constant true
38 // CHECK-DAG: %[[MASK:.*]]:2 = hlfir.declare %[[ARG0]]
39 // CHECK-DAG: %[[DIM_VAR:.*]]:2 = hlfir.declare %[[ARG2]]
40 // CHECK-DAG: %[[RES:.*]]:2 = hlfir.declare %[[ARG1]]
42 // CHECK-DAG: %[[RET_BOX:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x!fir.logical<4>>>>
43 // CHECK-DAG: %[[RET_ADDR:.*]] = fir.zero_bits !fir.heap<!fir.array<?x!fir.logical<4>>>
44 // CHECK-DAG: %[[C0:.*]] = arith.constant 0 : index
45 // CHECK-DAG: %[[RET_SHAPE:.*]] = fir.shape %[[C0]] : (index) -> !fir.shape<1>
46 // CHECK-DAG: %[[RET_EMBOX:.*]] = fir.embox %[[RET_ADDR]](%[[RET_SHAPE]])
47 // CHECK-DAG: fir.store %[[RET_EMBOX]] to %[[RET_BOX]]
49 // CHECK-DAG: %[[DIM:.*]] = fir.load %[[DIM_VAR]]#0 : !fir.ref<i32>
50 // CHECK-DAG: %[[RET_ARG:.*]] = fir.convert %[[RET_BOX]]
51 // CHECK-DAG: %[[MASK_ARG:.*]] = fir.convert %[[MASK]]#1
53 // CHECK: fir.call @_FortranAAllDim(%[[RET_ARG]], %[[MASK_ARG]], %[[DIM]], %[[LOC_STR:.*]], %[[LOC_N:.*]]) : (!fir.ref<!fir.box<none>>, !fir.box<none>, i32, !fir.ref<i8>, i32) -> ()
54 // CHECK: %[[RET:.*]] = fir.load %[[RET_BOX]]
55 // CHECK: %[[BOX_DIMS:.*]]:3 = fir.box_dims %[[RET]]
56 // CHECK-NEXT: %[[ADDR:.*]] = fir.box_addr %[[RET]]
57 // CHECK-NEXT: %[[SHIFT:.*]] = fir.shape_shift %[[BOX_DIMS]]#0, %[[BOX_DIMS]]#1
58 // CHECK-NEXT: %[[TMP:.*]]:2 = hlfir.declare %[[ADDR]](%[[SHIFT]]) {uniq_name = ".tmp.intrinsic_result"}
59 // CHECK: %[[EXPR:.*]] = hlfir.as_expr %[[TMP]]#0 move %[[TRUE]] : (!fir.box<!fir.array<?x!fir.logical<4>>>, i1) -> !hlfir.expr<?x!fir.logical<4>>
60 // CHECK: hlfir.assign %[[EXPR]] to %[[RES]]#0
61 // CHECK: hlfir.destroy %[[EXPR]]
65 func.func @_QPall3(%arg0: !fir.ref<!fir.array<2x!fir.logical<4>>> {fir.bindc_name = "s"}) {
66 %0 = fir.address_of(@_QFall3Ea) : !fir.ref<!fir.array<2x2x!fir.logical<4>>>
67 %c2 = arith.constant 2 : index
68 %c2_0 = arith.constant 2 : index
69 %1 = fir.shape %c2, %c2_0 : (index, index) -> !fir.shape<2>
70 %2:2 = hlfir.declare %0(%1) {uniq_name = "_QFall3Ea"} : (!fir.ref<!fir.array<2x2x!fir.logical<4>>>, !fir.shape<2>) -> (!fir.ref<!fir.array<2x2x!fir.logical<4>>>, !fir.ref<!fir.array<2x2x!fir.logical<4>>>)
71 %c2_1 = arith.constant 2 : index
72 %3 = fir.shape %c2_1 : (index) -> !fir.shape<1>
73 %4:2 = hlfir.declare %arg0(%3) {uniq_name = "_QFall3Es"} : (!fir.ref<!fir.array<2x!fir.logical<4>>>, !fir.shape<1>) -> (!fir.ref<!fir.array<2x!fir.logical<4>>>, !fir.ref<!fir.array<2x!fir.logical<4>>>)
74 %c1_i32 = arith.constant 1 : i32
75 %5 = hlfir.all %2#0 dim %c1_i32 : (!fir.ref<!fir.array<2x2x!fir.logical<4>>>, i32) -> !hlfir.expr<2x!fir.logical<4>>
76 hlfir.assign %5 to %4#0 : !hlfir.expr<2x!fir.logical<4>>, !fir.ref<!fir.array<2x!fir.logical<4>>>
77 hlfir.destroy %5 : !hlfir.expr<2x!fir.logical<4>>
80 // CHECK-LABEL: func.func @_QPall3(
81 // CHECK: %[[ARG0:.*]]: !fir.ref<!fir.array<2x!fir.logical<4>>>
82 // CHECK-DAG: %[[TRUE:.*]] = arith.constant true
83 // CHECK-DAG: %[[RET_BOX:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x!fir.logical<4>>>>
84 // CHECK-DAG: %[[RET_ADDR:.*]] = fir.zero_bits !fir.heap<!fir.array<?x!fir.logical<4>>>
85 // CHECK-DAG: %[[C0:.*]] = arith.constant 0 : index
86 // CHECK-DAG: %[[RET_SHAPE:.*]] = fir.shape %[[C0]] : (index) -> !fir.shape<1>
87 // CHECK-DAG: %[[RET_EMBOX:.*]] = fir.embox %[[RET_ADDR]](%[[RET_SHAPE]])
88 // CHECK-DAG: fir.store %[[RET_EMBOX]] to %[[RET_BOX]]
89 // CHECK-DAG: %[[RES:.*]]:2 = hlfir.declare %[[ARG0]](%[[RES_SHAPE:.*]])
91 // CHECK-DAG: %[[MASK_ADDR:.*]] = fir.address_of
92 // CHECK-DAG: %[[MASK_VAR:.*]]:2 = hlfir.declare %[[MASK_ADDR]](%[[MASK_SHAPE:.*]])
93 // CHECK-DAG: %[[MASK_BOX:.*]] = fir.embox %[[MASK_VAR]]#1(%[[MASK_SHAPE:.*]])
95 // CHECK-DAG: %[[DIM:.*]] = arith.constant 1 : i32
97 // CHECK-DAG: %[[RET_ARG:.*]] = fir.convert %[[RET_BOX]]
98 // CHECK-DAG: %[[MASK_ARG:.*]] = fir.convert %[[MASK_BOX]] : (!fir.box<!fir.array<2x2x!fir.logical<4>>>) -> !fir.box<none>
99 // CHECK: fir.call @_FortranAAllDim(%[[RET_ARG]], %[[MASK_ARG]], %[[DIM]], %[[LOC_STR:.*]], %[[LOC_N:.*]])
100 // CHECK: %[[RET:.*]] = fir.load %[[RET_BOX]]
101 // CHECK: %[[BOX_DIMS:.*]]:3 = fir.box_dims %[[RET]]
102 // CHECK-NEXT: %[[ADDR:.*]] = fir.box_addr %[[RET]]
103 // CHECK-NEXT: %[[SHIFT:.*]] = fir.shape_shift %[[BOX_DIMS]]#0, %[[BOX_DIMS]]#1
104 // CHECK-NEXT: %[[TMP:.*]]:2 = hlfir.declare %[[ADDR]](%[[SHIFT]]) {uniq_name = ".tmp.intrinsic_result"}
105 // CHECK: %[[EXPR:.*]] = hlfir.as_expr %[[TMP]]#0 move %[[TRUE]] : (!fir.box<!fir.array<?x!fir.logical<4>>>, i1) -> !hlfir.expr<?x!fir.logical<4>>
106 // CHECK: hlfir.assign %[[EXPR]] to %[[RES]]
107 // CHECK: hlfir.destroy %[[EXPR]]
108 // CHECK-NEXT: return
111 func.func @_QPall4(%arg0: !fir.box<!fir.array<?x?x!fir.logical<4>>> {fir.bindc_name = "a"}, %arg1: !fir.box<!fir.array<?x!fir.logical<4>>> {fir.bindc_name = "s"}, %arg2: !fir.ref<!fir.box<!fir.ptr<i32>>> {fir.bindc_name = "d"}) {
112 %0:2 = hlfir.declare %arg0 {uniq_name = "_QFall4Ea"} : (!fir.box<!fir.array<?x?x!fir.logical<4>>>) -> (!fir.box<!fir.array<?x?x!fir.logical<4>>>, !fir.box<!fir.array<?x?x!fir.logical<4>>>)
113 %1:2 = hlfir.declare %arg2 {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFall4Ed"} : (!fir.ref<!fir.box<!fir.ptr<i32>>>) -> (!fir.ref<!fir.box<!fir.ptr<i32>>>, !fir.ref<!fir.box<!fir.ptr<i32>>>)
114 %2:2 = hlfir.declare %arg1 {uniq_name = "_QFall4Es"} : (!fir.box<!fir.array<?x!fir.logical<4>>>) -> (!fir.box<!fir.array<?x!fir.logical<4>>>, !fir.box<!fir.array<?x!fir.logical<4>>>)
115 %3 = fir.load %1#0 : !fir.ref<!fir.box<!fir.ptr<i32>>>
116 %4 = fir.box_addr %3 : (!fir.box<!fir.ptr<i32>>) -> !fir.ptr<i32>
117 %5 = fir.load %4 : !fir.ptr<i32>
118 %6 = hlfir.no_reassoc %5 : i32
119 %7 = hlfir.all %0#0 dim %6 : (!fir.box<!fir.array<?x?x!fir.logical<4>>>, i32) -> !hlfir.expr<?x!fir.logical<4>>
120 hlfir.assign %7 to %2#0 : !hlfir.expr<?x!fir.logical<4>>, !fir.box<!fir.array<?x!fir.logical<4>>>
121 hlfir.destroy %7 : !hlfir.expr<?x!fir.logical<4>>
124 // CHECK-LABEL: func.func @_QPall4(
125 // CHECK: %[[ARG0:.*]]: !fir.box<!fir.array<?x?x!fir.logical<4>>>
126 // CHECK: %[[ARG1:.*]]: !fir.box<!fir.array<?x!fir.logical<4>>>
127 // CHECK: %[[ARG2:.*]]: !fir.ref<!fir.box<!fir.ptr<i32>>>
128 // CHECK-DAG: %[[TRUE:.*]] = arith.constant true
129 // CHECK-DAG: %[[MASK:.*]]:2 = hlfir.declare %[[ARG0]]
130 // CHECK-DAG: %[[DIM_ARG:.*]]:2 = hlfir.declare %[[ARG2]]
131 // CHECK-DAG: %[[RES:.*]]:2 = hlfir.declare %[[ARG1]]
133 // CHECK-DAG: %[[RET_BOX:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x!fir.logical<4>>>>
134 // CHECK-DAG: %[[DIM_PTR:.*]] = fir.load %[[DIM_ARG]]#0 : !fir.ref<!fir.box<!fir.ptr<i32>>>
135 // CHECK-DAG: %[[DIM_ADDR:.*]] = fir.box_addr %[[DIM_PTR]]
136 // CHECK-DAG: %[[DIM_VAR:.*]] = fir.load %[[DIM_ADDR]]
137 // CHECK-DAG: %[[DIM:.*]] = hlfir.no_reassoc %[[DIM_VAR]]
139 // CHECK-DAG: %[[C0:.*]] = arith.constant 0 : index
140 // CHECK-DAG: %[[RET_ADDR:.*]] = fir.zero_bits !fir.heap<!fir.array<?x!fir.logical<4>>>
141 // CHECK-DAG: %[[RET_SHAPE:.*]] = fir.shape %[[C0]] : (index) -> !fir.shape<1>
142 // CHECK-DAG: %[[RET_EMBOX:.*]] = fir.embox %[[RET_ADDR]](%[[RET_SHAPE]])
143 // CHECK-DAG: fir.store %[[RET_EMBOX]] to %[[RET_BOX]]
144 // CHECK-DAG: %[[RET_ARG:.*]] = fir.convert %[[RET_BOX]]
145 // CHECK-DAG: %[[MASK_ARG:.*]] = fir.convert %[[MASK]]#1
147 // CHECK: fir.call @_FortranAAllDim(%[[RET_ARG]], %[[MASK_ARG]], %[[DIM]], %[[LOC_STR:.*]], %[[LOC_N:.*]]) : (!fir.ref<!fir.box<none>>, !fir.box<none>, i32, !fir.ref<i8>, i32) -> ()
148 // CHECK: %[[RET:.*]] = fir.load %[[RET_BOX]]
149 // CHECK: %[[BOX_DIMS:.*]]:3 = fir.box_dims %[[RET]]
150 // CHECK-NEXT: %[[ADDR:.*]] = fir.box_addr %[[RET]]
151 // CHECK-NEXT: %[[SHIFT:.*]] = fir.shape_shift %[[BOX_DIMS]]#0, %[[BOX_DIMS]]#1
152 // CHECK-NEXT: %[[TMP:.*]]:2 = hlfir.declare %[[ADDR]](%[[SHIFT]]) {uniq_name = ".tmp.intrinsic_result"}
153 // CHECK: %[[EXPR:.*]] = hlfir.as_expr %[[TMP]]#0 move %[[TRUE]] : (!fir.box<!fir.array<?x!fir.logical<4>>>, i1) -> !hlfir.expr<?x!fir.logical<4>>
154 // CHECK: hlfir.assign %[[EXPR]] to %[[RES]]
155 // CHECK: hlfir.destroy %[[EXPR]]
156 // CHECK-NEXT: return