1 // Test inlining of hlfir.assign of arrays:
2 // RUN: fir-opt --inline-hlfir-assign %s | FileCheck %s
4 // The two assigns come from the following source forms:
7 func.func @_QPtest1(%arg0: !fir.ref<!fir.array<3x3xf32>> {fir.bindc_name = "x"}) {
8 %c1 = arith.constant 1 : index
9 %c3 = arith.constant 3 : index
10 %0 = fir.shape %c3, %c3 : (index, index) -> !fir.shape<2>
11 %1:2 = hlfir.declare %arg0(%0) {uniq_name = "_QFtest1Ex"} : (!fir.ref<!fir.array<3x3xf32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<3x3xf32>>, !fir.ref<!fir.array<3x3xf32>>)
12 %2 = fir.alloca !fir.array<3x3xf32> {bindc_name = "y", uniq_name = "_QFtest1Ey"}
13 %3:2 = hlfir.declare %2(%0) {uniq_name = "_QFtest1Ey"} : (!fir.ref<!fir.array<3x3xf32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<3x3xf32>>, !fir.ref<!fir.array<3x3xf32>>)
14 %4 = hlfir.designate %1#0 (%c1:%c3:%c1, %c1:%c3:%c1) shape %0 : (!fir.ref<!fir.array<3x3xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.ref<!fir.array<3x3xf32>>
15 %5 = hlfir.designate %3#0 (%c1:%c3:%c1, %c1:%c3:%c1) shape %0 : (!fir.ref<!fir.array<3x3xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.ref<!fir.array<3x3xf32>>
16 hlfir.assign %4 to %5 : !fir.ref<!fir.array<3x3xf32>>, !fir.ref<!fir.array<3x3xf32>>
17 hlfir.assign %1#0 to %3#0 : !fir.ref<!fir.array<3x3xf32>>, !fir.ref<!fir.array<3x3xf32>>
20 // CHECK-LABEL: func.func @_QPtest1(
21 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<3x3xf32>> {fir.bindc_name = "x"}) {
22 // CHECK: %[[VAL_1:.*]] = arith.constant 1 : index
23 // CHECK: %[[VAL_2:.*]] = arith.constant 3 : index
24 // CHECK: %[[VAL_3:.*]] = fir.shape %[[VAL_2]], %[[VAL_2]] : (index, index) -> !fir.shape<2>
25 // CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0]](%[[VAL_3]]) {uniq_name = "_QFtest1Ex"} : (!fir.ref<!fir.array<3x3xf32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<3x3xf32>>, !fir.ref<!fir.array<3x3xf32>>)
26 // CHECK: %[[VAL_5:.*]] = fir.alloca !fir.array<3x3xf32> {bindc_name = "y", uniq_name = "_QFtest1Ey"}
27 // CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_5]](%[[VAL_3]]) {uniq_name = "_QFtest1Ey"} : (!fir.ref<!fir.array<3x3xf32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<3x3xf32>>, !fir.ref<!fir.array<3x3xf32>>)
28 // CHECK: %[[VAL_7:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_1]]:%[[VAL_2]]:%[[VAL_1]], %[[VAL_1]]:%[[VAL_2]]:%[[VAL_1]]) shape %[[VAL_3]] : (!fir.ref<!fir.array<3x3xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.ref<!fir.array<3x3xf32>>
29 // CHECK: %[[VAL_8:.*]] = hlfir.designate %[[VAL_6]]#0 (%[[VAL_1]]:%[[VAL_2]]:%[[VAL_1]], %[[VAL_1]]:%[[VAL_2]]:%[[VAL_1]]) shape %[[VAL_3]] : (!fir.ref<!fir.array<3x3xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.ref<!fir.array<3x3xf32>>
30 // CHECK: fir.do_loop %[[VAL_9:.*]] = %[[VAL_1]] to %[[VAL_2]] step %[[VAL_1]] unordered {
31 // CHECK: fir.do_loop %[[VAL_10:.*]] = %[[VAL_1]] to %[[VAL_2]] step %[[VAL_1]] unordered {
32 // CHECK: %[[VAL_11:.*]] = hlfir.designate %[[VAL_7]] (%[[VAL_10]], %[[VAL_9]]) : (!fir.ref<!fir.array<3x3xf32>>, index, index) -> !fir.ref<f32>
33 // CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_11]] : !fir.ref<f32>
34 // CHECK: %[[VAL_13:.*]] = hlfir.designate %[[VAL_8]] (%[[VAL_10]], %[[VAL_9]]) : (!fir.ref<!fir.array<3x3xf32>>, index, index) -> !fir.ref<f32>
35 // CHECK: hlfir.assign %[[VAL_12]] to %[[VAL_13]] : f32, !fir.ref<f32>
38 // CHECK: fir.do_loop %[[VAL_14:.*]] = %[[VAL_1]] to %[[VAL_2]] step %[[VAL_1]] unordered {
39 // CHECK: fir.do_loop %[[VAL_15:.*]] = %[[VAL_1]] to %[[VAL_2]] step %[[VAL_1]] unordered {
40 // CHECK: %[[VAL_16:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_15]], %[[VAL_14]]) : (!fir.ref<!fir.array<3x3xf32>>, index, index) -> !fir.ref<f32>
41 // CHECK: %[[VAL_17:.*]] = fir.load %[[VAL_16]] : !fir.ref<f32>
42 // CHECK: %[[VAL_18:.*]] = hlfir.designate %[[VAL_6]]#0 (%[[VAL_15]], %[[VAL_14]]) : (!fir.ref<!fir.array<3x3xf32>>, index, index) -> !fir.ref<f32>
43 // CHECK: hlfir.assign %[[VAL_17]] to %[[VAL_18]] : f32, !fir.ref<f32>
50 func.func @_QPtest2(%arg0: !fir.box<!fir.array<?x?xf32>> {fir.bindc_name = "x"}) {
51 %c0 = arith.constant 0 : index
52 %c1 = arith.constant 1 : index
53 %c3 = arith.constant 3 : index
54 %0:2 = hlfir.declare %arg0 {uniq_name = "_QFtest2Ex"} : (!fir.box<!fir.array<?x?xf32>>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.box<!fir.array<?x?xf32>>)
55 %1 = fir.alloca !fir.array<3x3xf32> {bindc_name = "y", uniq_name = "_QFtest2Ey"}
56 %2 = fir.shape %c3, %c3 : (index, index) -> !fir.shape<2>
57 %3:2 = hlfir.declare %1(%2) {uniq_name = "_QFtest2Ey"} : (!fir.ref<!fir.array<3x3xf32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<3x3xf32>>, !fir.ref<!fir.array<3x3xf32>>)
58 %4:3 = fir.box_dims %0#1, %c0 : (!fir.box<!fir.array<?x?xf32>>, index) -> (index, index, index)
59 %5:3 = fir.box_dims %0#1, %c1 : (!fir.box<!fir.array<?x?xf32>>, index) -> (index, index, index)
60 %6 = arith.cmpi sgt, %4#1, %c0 : index
61 %7 = arith.select %6, %4#1, %c0 : index
62 %8 = arith.cmpi sgt, %5#1, %c0 : index
63 %9 = arith.select %8, %5#1, %c0 : index
64 %10 = fir.shape %7, %9 : (index, index) -> !fir.shape<2>
65 %11 = hlfir.designate %0#0 (%c1:%4#1:%c1, %c1:%5#1:%c1) shape %10 : (!fir.box<!fir.array<?x?xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>>
66 %12 = hlfir.designate %3#0 (%c1:%c3:%c1, %c1:%c3:%c1) shape %2 : (!fir.ref<!fir.array<3x3xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.ref<!fir.array<3x3xf32>>
67 hlfir.assign %11 to %12 : !fir.box<!fir.array<?x?xf32>>, !fir.ref<!fir.array<3x3xf32>>
68 hlfir.assign %0#0 to %3#0 : !fir.box<!fir.array<?x?xf32>>, !fir.ref<!fir.array<3x3xf32>>
71 // CHECK-LABEL: func.func @_QPtest2(
72 // CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x?xf32>> {fir.bindc_name = "x"}) {
73 // CHECK: %[[VAL_1:.*]] = arith.constant 0 : index
74 // CHECK: %[[VAL_2:.*]] = arith.constant 1 : index
75 // CHECK: %[[VAL_3:.*]] = arith.constant 3 : index
76 // CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest2Ex"} : (!fir.box<!fir.array<?x?xf32>>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.box<!fir.array<?x?xf32>>)
77 // CHECK: %[[VAL_5:.*]] = fir.alloca !fir.array<3x3xf32> {bindc_name = "y", uniq_name = "_QFtest2Ey"}
78 // CHECK: %[[VAL_6:.*]] = fir.shape %[[VAL_3]], %[[VAL_3]] : (index, index) -> !fir.shape<2>
79 // CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_5]](%[[VAL_6]]) {uniq_name = "_QFtest2Ey"} : (!fir.ref<!fir.array<3x3xf32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<3x3xf32>>, !fir.ref<!fir.array<3x3xf32>>)
80 // CHECK: %[[VAL_8:.*]]:3 = fir.box_dims %[[VAL_4]]#1, %[[VAL_1]] : (!fir.box<!fir.array<?x?xf32>>, index) -> (index, index, index)
81 // CHECK: %[[VAL_9:.*]]:3 = fir.box_dims %[[VAL_4]]#1, %[[VAL_2]] : (!fir.box<!fir.array<?x?xf32>>, index) -> (index, index, index)
82 // CHECK: %[[VAL_10:.*]] = arith.cmpi sgt, %[[VAL_8]]#1, %[[VAL_1]] : index
83 // CHECK: %[[VAL_11:.*]] = arith.select %[[VAL_10]], %[[VAL_8]]#1, %[[VAL_1]] : index
84 // CHECK: %[[VAL_12:.*]] = arith.cmpi sgt, %[[VAL_9]]#1, %[[VAL_1]] : index
85 // CHECK: %[[VAL_13:.*]] = arith.select %[[VAL_12]], %[[VAL_9]]#1, %[[VAL_1]] : index
86 // CHECK: %[[VAL_14:.*]] = fir.shape %[[VAL_11]], %[[VAL_13]] : (index, index) -> !fir.shape<2>
87 // CHECK: %[[VAL_15:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_2]]:%[[VAL_8]]#1:%[[VAL_2]], %[[VAL_2]]:%[[VAL_9]]#1:%[[VAL_2]]) shape %[[VAL_14]] : (!fir.box<!fir.array<?x?xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>>
88 // CHECK: %[[VAL_16:.*]] = hlfir.designate %[[VAL_7]]#0 (%[[VAL_2]]:%[[VAL_3]]:%[[VAL_2]], %[[VAL_2]]:%[[VAL_3]]:%[[VAL_2]]) shape %[[VAL_6]] : (!fir.ref<!fir.array<3x3xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.ref<!fir.array<3x3xf32>>
89 // CHECK: fir.do_loop %[[VAL_17:.*]] = %[[VAL_2]] to %[[VAL_3]] step %[[VAL_2]] unordered {
90 // CHECK: fir.do_loop %[[VAL_18:.*]] = %[[VAL_2]] to %[[VAL_3]] step %[[VAL_2]] unordered {
91 // CHECK: %[[VAL_19:.*]] = hlfir.designate %[[VAL_15]] (%[[VAL_18]], %[[VAL_17]]) : (!fir.box<!fir.array<?x?xf32>>, index, index) -> !fir.ref<f32>
92 // CHECK: %[[VAL_20:.*]] = fir.load %[[VAL_19]] : !fir.ref<f32>
93 // CHECK: %[[VAL_21:.*]] = hlfir.designate %[[VAL_16]] (%[[VAL_18]], %[[VAL_17]]) : (!fir.ref<!fir.array<3x3xf32>>, index, index) -> !fir.ref<f32>
94 // CHECK: hlfir.assign %[[VAL_20]] to %[[VAL_21]] : f32, !fir.ref<f32>
97 // CHECK: fir.do_loop %[[VAL_22:.*]] = %[[VAL_2]] to %[[VAL_3]] step %[[VAL_2]] unordered {
98 // CHECK: fir.do_loop %[[VAL_23:.*]] = %[[VAL_2]] to %[[VAL_3]] step %[[VAL_2]] unordered {
99 // CHECK: %[[VAL_24:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_23]], %[[VAL_22]]) : (!fir.box<!fir.array<?x?xf32>>, index, index) -> !fir.ref<f32>
100 // CHECK: %[[VAL_25:.*]] = fir.load %[[VAL_24]] : !fir.ref<f32>
101 // CHECK: %[[VAL_26:.*]] = hlfir.designate %[[VAL_7]]#0 (%[[VAL_23]], %[[VAL_22]]) : (!fir.ref<!fir.array<3x3xf32>>, index, index) -> !fir.ref<f32>
102 // CHECK: hlfir.assign %[[VAL_25]] to %[[VAL_26]] : f32, !fir.ref<f32>
109 func.func @_QPtest3(%arg0: !fir.box<!fir.array<?x?xf32>> {fir.bindc_name = "x"}) {
110 %c0 = arith.constant 0 : index
111 %c1 = arith.constant 1 : index
112 %c3 = arith.constant 3 : index
113 %0:2 = hlfir.declare %arg0 {uniq_name = "_QFtest3Ex"} : (!fir.box<!fir.array<?x?xf32>>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.box<!fir.array<?x?xf32>>)
114 %1 = fir.alloca !fir.array<3x3xf32> {bindc_name = "y", uniq_name = "_QFtest3Ey"}
115 %2 = fir.shape %c3, %c3 : (index, index) -> !fir.shape<2>
116 %3:2 = hlfir.declare %1(%2) {uniq_name = "_QFtest3Ey"} : (!fir.ref<!fir.array<3x3xf32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<3x3xf32>>, !fir.ref<!fir.array<3x3xf32>>)
117 %4 = hlfir.designate %3#0 (%c1:%c3:%c1, %c1:%c3:%c1) shape %2 : (!fir.ref<!fir.array<3x3xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.ref<!fir.array<3x3xf32>>
118 %5:3 = fir.box_dims %0#1, %c0 : (!fir.box<!fir.array<?x?xf32>>, index) -> (index, index, index)
119 %6:3 = fir.box_dims %0#1, %c1 : (!fir.box<!fir.array<?x?xf32>>, index) -> (index, index, index)
120 %7 = arith.cmpi sgt, %5#1, %c0 : index
121 %8 = arith.select %7, %5#1, %c0 : index
122 %9 = arith.cmpi sgt, %6#1, %c0 : index
123 %10 = arith.select %9, %6#1, %c0 : index
124 %11 = fir.shape %8, %10 : (index, index) -> !fir.shape<2>
125 %12 = hlfir.designate %0#0 (%c1:%5#1:%c1, %c1:%6#1:%c1) shape %11 : (!fir.box<!fir.array<?x?xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>>
126 hlfir.assign %4 to %12 : !fir.ref<!fir.array<3x3xf32>>, !fir.box<!fir.array<?x?xf32>>
127 hlfir.assign %3#0 to %0#0 : !fir.ref<!fir.array<3x3xf32>>, !fir.box<!fir.array<?x?xf32>>
130 // CHECK-LABEL: func.func @_QPtest3(
131 // CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x?xf32>> {fir.bindc_name = "x"}) {
132 // CHECK: %[[VAL_1:.*]] = arith.constant 0 : index
133 // CHECK: %[[VAL_2:.*]] = arith.constant 1 : index
134 // CHECK: %[[VAL_3:.*]] = arith.constant 3 : index
135 // CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFtest3Ex"} : (!fir.box<!fir.array<?x?xf32>>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.box<!fir.array<?x?xf32>>)
136 // CHECK: %[[VAL_5:.*]] = fir.alloca !fir.array<3x3xf32> {bindc_name = "y", uniq_name = "_QFtest3Ey"}
137 // CHECK: %[[VAL_6:.*]] = fir.shape %[[VAL_3]], %[[VAL_3]] : (index, index) -> !fir.shape<2>
138 // CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_5]](%[[VAL_6]]) {uniq_name = "_QFtest3Ey"} : (!fir.ref<!fir.array<3x3xf32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<3x3xf32>>, !fir.ref<!fir.array<3x3xf32>>)
139 // CHECK: %[[VAL_8:.*]] = hlfir.designate %[[VAL_7]]#0 (%[[VAL_2]]:%[[VAL_3]]:%[[VAL_2]], %[[VAL_2]]:%[[VAL_3]]:%[[VAL_2]]) shape %[[VAL_6]] : (!fir.ref<!fir.array<3x3xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.ref<!fir.array<3x3xf32>>
140 // CHECK: %[[VAL_9:.*]]:3 = fir.box_dims %[[VAL_4]]#1, %[[VAL_1]] : (!fir.box<!fir.array<?x?xf32>>, index) -> (index, index, index)
141 // CHECK: %[[VAL_10:.*]]:3 = fir.box_dims %[[VAL_4]]#1, %[[VAL_2]] : (!fir.box<!fir.array<?x?xf32>>, index) -> (index, index, index)
142 // CHECK: %[[VAL_11:.*]] = arith.cmpi sgt, %[[VAL_9]]#1, %[[VAL_1]] : index
143 // CHECK: %[[VAL_12:.*]] = arith.select %[[VAL_11]], %[[VAL_9]]#1, %[[VAL_1]] : index
144 // CHECK: %[[VAL_13:.*]] = arith.cmpi sgt, %[[VAL_10]]#1, %[[VAL_1]] : index
145 // CHECK: %[[VAL_14:.*]] = arith.select %[[VAL_13]], %[[VAL_10]]#1, %[[VAL_1]] : index
146 // CHECK: %[[VAL_15:.*]] = fir.shape %[[VAL_12]], %[[VAL_14]] : (index, index) -> !fir.shape<2>
147 // CHECK: %[[VAL_16:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_2]]:%[[VAL_9]]#1:%[[VAL_2]], %[[VAL_2]]:%[[VAL_10]]#1:%[[VAL_2]]) shape %[[VAL_15]] : (!fir.box<!fir.array<?x?xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>>
148 // CHECK: fir.do_loop %[[VAL_17:.*]] = %[[VAL_2]] to %[[VAL_14]] step %[[VAL_2]] unordered {
149 // CHECK: fir.do_loop %[[VAL_18:.*]] = %[[VAL_2]] to %[[VAL_12]] step %[[VAL_2]] unordered {
150 // CHECK: %[[VAL_19:.*]] = hlfir.designate %[[VAL_8]] (%[[VAL_18]], %[[VAL_17]]) : (!fir.ref<!fir.array<3x3xf32>>, index, index) -> !fir.ref<f32>
151 // CHECK: %[[VAL_20:.*]] = fir.load %[[VAL_19]] : !fir.ref<f32>
152 // CHECK: %[[VAL_21:.*]] = hlfir.designate %[[VAL_16]] (%[[VAL_18]], %[[VAL_17]]) : (!fir.box<!fir.array<?x?xf32>>, index, index) -> !fir.ref<f32>
153 // CHECK: hlfir.assign %[[VAL_20]] to %[[VAL_21]] : f32, !fir.ref<f32>
156 // CHECK: %[[VAL_22:.*]]:3 = fir.box_dims %[[VAL_4]]#0, %[[VAL_1]] : (!fir.box<!fir.array<?x?xf32>>, index) -> (index, index, index)
157 // CHECK: %[[VAL_23:.*]]:3 = fir.box_dims %[[VAL_4]]#0, %[[VAL_2]] : (!fir.box<!fir.array<?x?xf32>>, index) -> (index, index, index)
158 // CHECK: fir.do_loop %[[VAL_24:.*]] = %[[VAL_2]] to %[[VAL_23]]#1 step %[[VAL_2]] unordered {
159 // CHECK: fir.do_loop %[[VAL_25:.*]] = %[[VAL_2]] to %[[VAL_22]]#1 step %[[VAL_2]] unordered {
160 // CHECK: %[[VAL_26:.*]] = hlfir.designate %[[VAL_7]]#0 (%[[VAL_25]], %[[VAL_24]]) : (!fir.ref<!fir.array<3x3xf32>>, index, index) -> !fir.ref<f32>
161 // CHECK: %[[VAL_27:.*]] = fir.load %[[VAL_26]] : !fir.ref<f32>
162 // CHECK: %[[VAL_28:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_25]], %[[VAL_24]]) : (!fir.box<!fir.array<?x?xf32>>, index, index) -> !fir.ref<f32>
163 // CHECK: hlfir.assign %[[VAL_27]] to %[[VAL_28]] : f32, !fir.ref<f32>
170 // The LHS is a whole allocatable, so the assignment may imply
171 // allocation. This is not currently supported.
172 func.func @_QPtest4(%arg0: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>> {fir.bindc_name = "x"}) {
173 %c3 = arith.constant 3 : index
174 %0:2 = hlfir.declare %arg0 {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest4Ex"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>)
175 %1 = fir.alloca !fir.array<3x3xf32> {bindc_name = "y", uniq_name = "_QFtest4Ey"}
176 %2 = fir.shape %c3, %c3 : (index, index) -> !fir.shape<2>
177 %3:2 = hlfir.declare %1(%2) {uniq_name = "_QFtest4Ey"} : (!fir.ref<!fir.array<3x3xf32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<3x3xf32>>, !fir.ref<!fir.array<3x3xf32>>)
178 hlfir.assign %3#0 to %0#0 realloc : !fir.ref<!fir.array<3x3xf32>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>
181 // CHECK-LABEL: func.func @_QPtest4(
182 // CHECK-NOT: hlfir.assign
183 // CHECK: hlfir.assign %{{.*}} to %{{.*}} realloc : !fir.ref<!fir.array<3x3xf32>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>
184 // CHECK-NOT: hlfir.assign
187 // LHS is a pointer, but RHS is a subroutine local,
188 // so they cannot alias.
189 func.func @_QPtest5(%arg0: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>> {fir.bindc_name = "x"}) {
190 %c0 = arith.constant 0 : index
191 %c1 = arith.constant 1 : index
192 %c3 = arith.constant 3 : index
193 %0:2 = hlfir.declare %arg0 {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtest5Ex"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>)
194 %1 = fir.alloca !fir.array<3x3xf32> {bindc_name = "y", uniq_name = "_QFtest5Ey"}
195 %2 = fir.shape %c3, %c3 : (index, index) -> !fir.shape<2>
196 %3:2 = hlfir.declare %1(%2) {uniq_name = "_QFtest5Ey"} : (!fir.ref<!fir.array<3x3xf32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<3x3xf32>>, !fir.ref<!fir.array<3x3xf32>>)
197 %4 = hlfir.designate %3#0 (%c1:%c3:%c1, %c1:%c3:%c1) shape %2 : (!fir.ref<!fir.array<3x3xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.ref<!fir.array<3x3xf32>>
198 %5 = fir.load %0#0 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>
199 %6:3 = fir.box_dims %5, %c0 : (!fir.box<!fir.ptr<!fir.array<?x?xf32>>>, index) -> (index, index, index)
200 %7:3 = fir.box_dims %5, %c1 : (!fir.box<!fir.ptr<!fir.array<?x?xf32>>>, index) -> (index, index, index)
201 %8 = arith.addi %6#0, %6#1 : index
202 %9 = arith.subi %8, %c1 : index
203 %10 = arith.addi %7#0, %7#1 : index
204 %11 = arith.subi %10, %c1 : index
205 %12 = arith.subi %9, %6#0 : index
206 %13 = arith.addi %12, %c1 : index
207 %14 = arith.cmpi sgt, %13, %c0 : index
208 %15 = arith.select %14, %13, %c0 : index
209 %16 = arith.subi %11, %7#0 : index
210 %17 = arith.addi %16, %c1 : index
211 %18 = arith.cmpi sgt, %17, %c0 : index
212 %19 = arith.select %18, %17, %c0 : index
213 %20 = fir.shape %15, %19 : (index, index) -> !fir.shape<2>
214 %21 = hlfir.designate %5 (%6#0:%9:%c1, %7#0:%11:%c1) shape %20 : (!fir.box<!fir.ptr<!fir.array<?x?xf32>>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>>
215 hlfir.assign %4 to %21 : !fir.ref<!fir.array<3x3xf32>>, !fir.box<!fir.array<?x?xf32>>
216 %22 = fir.load %0#0 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>
217 hlfir.assign %3#0 to %22 : !fir.ref<!fir.array<3x3xf32>>, !fir.box<!fir.ptr<!fir.array<?x?xf32>>>
220 // CHECK-LABEL: func.func @_QPtest5(
221 // CHECK-NOT: hlfir.assign
222 // CHECK: hlfir.assign %{{.*}} to %{{.*}} : f32, !fir.ref<f32>
223 // CHECK-NOT: hlfir.assign
224 // CHECK: hlfir.assign %{{.*}} to %{{.*}} : f32, !fir.ref<f32>
225 // CHECK-NOT: hlfir.assign
228 // RHS is a pointer, but LHS is a subroutine local,
229 // so they cannot alias.
230 func.func @_QPtest6(%arg0: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>> {fir.bindc_name = "x"}) {
231 %c1 = arith.constant 1 : index
232 %c0 = arith.constant 0 : index
233 %c3 = arith.constant 3 : index
234 %0:2 = hlfir.declare %arg0 {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtest6Ex"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>)
235 %1 = fir.alloca !fir.array<3x3xf32> {bindc_name = "y", uniq_name = "_QFtest6Ey"}
236 %2 = fir.shape %c3, %c3 : (index, index) -> !fir.shape<2>
237 %3:2 = hlfir.declare %1(%2) {uniq_name = "_QFtest6Ey"} : (!fir.ref<!fir.array<3x3xf32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<3x3xf32>>, !fir.ref<!fir.array<3x3xf32>>)
238 %4 = fir.load %0#0 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>
239 %5:3 = fir.box_dims %4, %c0 : (!fir.box<!fir.ptr<!fir.array<?x?xf32>>>, index) -> (index, index, index)
240 %6:3 = fir.box_dims %4, %c1 : (!fir.box<!fir.ptr<!fir.array<?x?xf32>>>, index) -> (index, index, index)
241 %7 = arith.addi %5#0, %5#1 : index
242 %8 = arith.subi %7, %c1 : index
243 %9 = arith.addi %6#0, %6#1 : index
244 %10 = arith.subi %9, %c1 : index
245 %11 = arith.subi %8, %5#0 : index
246 %12 = arith.addi %11, %c1 : index
247 %13 = arith.cmpi sgt, %12, %c0 : index
248 %14 = arith.select %13, %12, %c0 : index
249 %15 = arith.subi %10, %6#0 : index
250 %16 = arith.addi %15, %c1 : index
251 %17 = arith.cmpi sgt, %16, %c0 : index
252 %18 = arith.select %17, %16, %c0 : index
253 %19 = fir.shape %14, %18 : (index, index) -> !fir.shape<2>
254 %20 = hlfir.designate %4 (%5#0:%8:%c1, %6#0:%10:%c1) shape %19 : (!fir.box<!fir.ptr<!fir.array<?x?xf32>>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>>
255 %21 = hlfir.designate %3#0 (%c1:%c3:%c1, %c1:%c3:%c1) shape %2 : (!fir.ref<!fir.array<3x3xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.ref<!fir.array<3x3xf32>>
256 hlfir.assign %20 to %21 : !fir.box<!fir.array<?x?xf32>>, !fir.ref<!fir.array<3x3xf32>>
257 %22 = fir.load %0#0 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>
258 hlfir.assign %22 to %3#0 : !fir.box<!fir.ptr<!fir.array<?x?xf32>>>, !fir.ref<!fir.array<3x3xf32>>
261 // CHECK-LABEL: func.func @_QPtest6(
262 // CHECK-NOT: hlfir.assign
263 // CHECK: hlfir.assign %{{.*}} to %{{.*}} : f32, !fir.ref<f32>
264 // CHECK-NOT: hlfir.assign
265 // CHECK: hlfir.assign %{{.*}} to %{{.*}} : f32, !fir.ref<f32>
266 // CHECK-NOT: hlfir.assign
269 // LHS and RHS do not alias, and the assignment cannot
270 // allocate/reallocate LHS, so we should be able to optimize.
271 func.func @_QPtest7(%arg0: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>> {fir.bindc_name = "x"}) {
272 %c0 = arith.constant 0 : index
273 %c1 = arith.constant 1 : index
274 %c3 = arith.constant 3 : index
275 %0:2 = hlfir.declare %arg0 {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest7Ex"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>)
276 %1 = fir.alloca !fir.array<3x3xf32> {bindc_name = "y", uniq_name = "_QFtest7Ey"}
277 %2 = fir.shape %c3, %c3 : (index, index) -> !fir.shape<2>
278 %3:2 = hlfir.declare %1(%2) {uniq_name = "_QFtest7Ey"} : (!fir.ref<!fir.array<3x3xf32>>, !fir.shape<2>) -> (!fir.ref<!fir.array<3x3xf32>>, !fir.ref<!fir.array<3x3xf32>>)
279 %4 = hlfir.designate %3#0 (%c1:%c3:%c1, %c1:%c3:%c1) shape %2 : (!fir.ref<!fir.array<3x3xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.ref<!fir.array<3x3xf32>>
280 %5 = fir.load %0#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>
281 %6:3 = fir.box_dims %5, %c0 : (!fir.box<!fir.heap<!fir.array<?x?xf32>>>, index) -> (index, index, index)
282 %7:3 = fir.box_dims %5, %c1 : (!fir.box<!fir.heap<!fir.array<?x?xf32>>>, index) -> (index, index, index)
283 %8 = arith.addi %6#0, %6#1 : index
284 %9 = arith.subi %8, %c1 : index
285 %10 = arith.addi %7#0, %7#1 : index
286 %11 = arith.subi %10, %c1 : index
287 %12 = arith.subi %9, %6#0 : index
288 %13 = arith.addi %12, %c1 : index
289 %14 = arith.cmpi sgt, %13, %c0 : index
290 %15 = arith.select %14, %13, %c0 : index
291 %16 = arith.subi %11, %7#0 : index
292 %17 = arith.addi %16, %c1 : index
293 %18 = arith.cmpi sgt, %17, %c0 : index
294 %19 = arith.select %18, %17, %c0 : index
295 %20 = fir.shape %15, %19 : (index, index) -> !fir.shape<2>
296 %21 = hlfir.designate %5 (%6#0:%9:%c1, %7#0:%11:%c1) shape %20 : (!fir.box<!fir.heap<!fir.array<?x?xf32>>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>>
297 hlfir.assign %4 to %21 : !fir.ref<!fir.array<3x3xf32>>, !fir.box<!fir.array<?x?xf32>>
300 // CHECK-LABEL: func.func @_QPtest7(
301 // CHECK-NOT: hlfir.assign
302 // CHECK: hlfir.assign %{{.*}} to %{{.*}} : f32, !fir.ref<f32>
303 // CHECK-NOT: hlfir.assign
306 // Test that VAR = EXPR assignment is inlined:
307 // subroutine test_expr_rhs(p1, p2)
308 // logical, pointer :: p1(:), p2(:)
310 // end subroutine test_expr_rhs
311 func.func @_QPtest_expr_rhs(%arg0: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>> {fir.bindc_name = "p1"}, %arg1: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>> {fir.bindc_name = "p2"}) {
312 %c1 = arith.constant 1 : index
313 %c0 = arith.constant 0 : index
314 %0 = fir.dummy_scope : !fir.dscope
315 %1:2 = hlfir.declare %arg0 dummy_scope %0 {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtest_expr_rhsEp1"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>)
316 %2:2 = hlfir.declare %arg1 dummy_scope %0 {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtest_expr_rhsEp2"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>)
317 %3 = fir.load %2#0 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>
318 %4:3 = fir.box_dims %3, %c0 : (!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>, index) -> (index, index, index)
319 %5 = fir.shape %4#1 : (index) -> !fir.shape<1>
320 %6 = hlfir.elemental %5 unordered : (!fir.shape<1>) -> !hlfir.expr<?x!fir.logical<4>> {
322 %8 = arith.subi %4#0, %c1 : index
323 %9 = arith.addi %arg2, %8 : index
324 %10 = hlfir.designate %3 (%9) : (!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>, index) -> !fir.ref<!fir.logical<4>>
325 %11 = fir.load %10 : !fir.ref<!fir.logical<4>>
326 %12 = hlfir.no_reassoc %11 : !fir.logical<4>
327 hlfir.yield_element %12 : !fir.logical<4>
329 %7 = fir.load %1#0 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>
330 hlfir.assign %6 to %7 : !hlfir.expr<?x!fir.logical<4>>, !fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>
331 hlfir.destroy %6 : !hlfir.expr<?x!fir.logical<4>>
334 // CHECK-LABEL: func.func @_QPtest_expr_rhs(
335 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>> {fir.bindc_name = "p1"},
336 // CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>> {fir.bindc_name = "p2"}) {
337 // CHECK: %[[VAL_2:.*]] = arith.constant 1 : index
338 // CHECK: %[[VAL_3:.*]] = arith.constant 0 : index
339 // CHECK: %[[VAL_4:.*]] = fir.dummy_scope : !fir.dscope
340 // CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_4]] {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtest_expr_rhsEp1"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>)
341 // CHECK: %[[VAL_10:.*]] = hlfir.elemental %{{.*}} unordered : (!fir.shape<1>) -> !hlfir.expr<?x!fir.logical<4>> {
343 // CHECK: %[[VAL_17:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>>
344 // CHECK: %[[VAL_18:.*]]:3 = fir.box_dims %[[VAL_17]], %[[VAL_3]] : (!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>, index) -> (index, index, index)
345 // CHECK: fir.do_loop %[[VAL_19:.*]] = %[[VAL_2]] to %[[VAL_18]]#1 step %[[VAL_2]] unordered {
346 // CHECK: %[[VAL_20:.*]] = hlfir.apply %[[VAL_10]], %[[VAL_19]] : (!hlfir.expr<?x!fir.logical<4>>, index) -> !fir.logical<4>
347 // CHECK: %[[VAL_21:.*]]:3 = fir.box_dims %[[VAL_17]], %[[VAL_3]] : (!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>, index) -> (index, index, index)
348 // CHECK: %[[VAL_22:.*]] = arith.subi %[[VAL_21]]#0, %[[VAL_2]] : index
349 // CHECK: %[[VAL_23:.*]] = arith.addi %[[VAL_19]], %[[VAL_22]] : index
350 // CHECK: %[[VAL_24:.*]] = hlfir.designate %[[VAL_17]] (%[[VAL_23]]) : (!fir.box<!fir.ptr<!fir.array<?x!fir.logical<4>>>>, index) -> !fir.ref<!fir.logical<4>>
351 // CHECK: hlfir.assign %[[VAL_20]] to %[[VAL_24]] : !fir.logical<4>, !fir.ref<!fir.logical<4>>
353 // CHECK: hlfir.destroy %[[VAL_10]] : !hlfir.expr<?x!fir.logical<4>>