[LLVM] Fix Maintainers.md formatting (NFC)
[llvm-project.git] / flang / test / HLFIR / opt-array-slice-assign.fir
blob11bd97c1158342bb216625cb7e3e6540b9a45cfe
1 // Test optimized bufferization for hlfir.assign of array
2 // slices, e.g.:
3 //   x(2:7999,1:120,new) = (x(2:7999,1:120,old))
4 // We can expand hlfir.assign if the slices are either identical
5 // or completely disjoint. In case they are identical, we still
6 // need to make sure that the one-based indices are used
7 // uniformly for both LHS and RHS.
8 // RUN: fir-opt --opt-bufferization %s | FileCheck %s
10 func.func @_QPtest1(%arg0: !fir.ref<!fir.array<8000x120x3xf32>> {fir.bindc_name = "x"}) {
11   %c7998 = arith.constant 7998 : index
12   %c1 = arith.constant 1 : index
13   %c7999 = arith.constant 7999 : index
14   %c2 = arith.constant 2 : index
15   %c3 = arith.constant 3 : index
16   %c120 = arith.constant 120 : index
17   %c8000 = arith.constant 8000 : index
18   %0 = fir.alloca i32 {bindc_name = "new", uniq_name = "_QFtest1Enew"}
19   %1:2 = hlfir.declare %0 {uniq_name = "_QFtest1Enew"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
20   %2 = fir.alloca i32 {bindc_name = "old", uniq_name = "_QFtest1Eold"}
21   %3:2 = hlfir.declare %2 {uniq_name = "_QFtest1Eold"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
22   %4 = fir.shape %c8000, %c120, %c3 : (index, index, index) -> !fir.shape<3>
23   %5:2 = hlfir.declare %arg0(%4) {uniq_name = "_QFtest1Ex"} : (!fir.ref<!fir.array<8000x120x3xf32>>, !fir.shape<3>) -> (!fir.ref<!fir.array<8000x120x3xf32>>, !fir.ref<!fir.array<8000x120x3xf32>>)
24   %6 = fir.load %3#0 : !fir.ref<i32>
25   %7 = fir.convert %6 : (i32) -> i64
26   %8 = fir.shape %c7998, %c120 : (index, index) -> !fir.shape<2>
27   %9 = hlfir.designate %5#0 (%c2:%c7999:%c1, %c1:%c120:%c1, %7)  shape %8 : (!fir.ref<!fir.array<8000x120x3xf32>>, index, index, index, index, index, index, i64, !fir.shape<2>) -> !fir.box<!fir.array<7998x120xf32>>
28   %10 = hlfir.elemental %8 unordered : (!fir.shape<2>) -> !hlfir.expr<7998x120xf32> {
29   ^bb0(%arg1: index, %arg2: index):
30     %14 = hlfir.designate %9 (%arg1, %arg2)  : (!fir.box<!fir.array<7998x120xf32>>, index, index) -> !fir.ref<f32>
31     %15 = fir.load %14 : !fir.ref<f32>
32     %16 = hlfir.no_reassoc %15 : f32
33     hlfir.yield_element %16 : f32
34   }
35   %11 = fir.load %1#0 : !fir.ref<i32>
36   %12 = fir.convert %11 : (i32) -> i64
37   %13 = hlfir.designate %5#0 (%c2:%c7999:%c1, %c1:%c120:%c1, %12)  shape %8 : (!fir.ref<!fir.array<8000x120x3xf32>>, index, index, index, index, index, index, i64, !fir.shape<2>) -> !fir.box<!fir.array<7998x120xf32>>
38   hlfir.assign %10 to %13 : !hlfir.expr<7998x120xf32>, !fir.box<!fir.array<7998x120xf32>>
39   hlfir.destroy %10 : !hlfir.expr<7998x120xf32>
40   return
42 // CHECK-LABEL:   func.func @_QPtest1(
43 // CHECK:           fir.do_loop %[[VAL_21:.*]] =
44 // CHECK:             fir.do_loop %[[VAL_22:.*]] =
45 // CHECK:               %[[VAL_23:.*]] = hlfir.designate %[[VAL_17:.*]] (%[[VAL_22]], %[[VAL_21]])  : (!fir.box<!fir.array<7998x120xf32>>, index, index) -> !fir.ref<f32>
46 // CHECK:               %[[VAL_24:.*]] = fir.load %[[VAL_23]] : !fir.ref<f32>
47 // CHECK:               %[[VAL_25:.*]] = hlfir.no_reassoc %[[VAL_24]] : f32
48 // CHECK:               %[[VAL_26:.*]] = hlfir.designate %[[VAL_20:.*]] (%[[VAL_22]], %[[VAL_21]])  : (!fir.box<!fir.array<7998x120xf32>>, index, index) -> !fir.ref<f32>
49 // CHECK:               hlfir.assign %[[VAL_25]] to %[[VAL_26]] : f32, !fir.ref<f32>
50 // CHECK:             }
51 // CHECK:           }
53 func.func @_QPtest2(%arg0: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?x?xf32>>>> {fir.bindc_name = "x"}) {
54   %c120 = arith.constant 120 : index
55   %c7998 = arith.constant 7998 : index
56   %c1 = arith.constant 1 : index
57   %c7999 = arith.constant 7999 : index
58   %c2 = arith.constant 2 : index
59   %0:2 = hlfir.declare %arg0 {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest2Ex"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?x?xf32>>>>) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?x?xf32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x?x?xf32>>>>)
60   %1 = fir.load %0#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?x?xf32>>>>
61   %2 = fir.shape %c7998, %c120 : (index, index) -> !fir.shape<2>
62   %3 = hlfir.designate %1 (%c2:%c7999:%c1, %c1:%c120:%c1, %c2)  shape %2 : (!fir.box<!fir.heap<!fir.array<?x?x?xf32>>>, index, index, index, index, index, index, index, !fir.shape<2>) -> !fir.box<!fir.array<7998x120xf32>>
63   %4 = hlfir.elemental %2 unordered : (!fir.shape<2>) -> !hlfir.expr<7998x120xf32> {
64   ^bb0(%arg1: index, %arg2: index):
65     %6 = hlfir.designate %3 (%arg1, %arg2)  : (!fir.box<!fir.array<7998x120xf32>>, index, index) -> !fir.ref<f32>
66     %7 = fir.load %6 : !fir.ref<f32>
67     %8 = hlfir.no_reassoc %7 : f32
68     hlfir.yield_element %8 : f32
69   }
70   %5 = hlfir.designate %1 (%c2:%c7999:%c1, %c1:%c120:%c1, %c1)  shape %2 : (!fir.box<!fir.heap<!fir.array<?x?x?xf32>>>, index, index, index, index, index, index, index, !fir.shape<2>) -> !fir.box<!fir.array<7998x120xf32>>
71   hlfir.assign %4 to %5 : !hlfir.expr<7998x120xf32>, !fir.box<!fir.array<7998x120xf32>>
72   hlfir.destroy %4 : !hlfir.expr<7998x120xf32>
73   return
75 // CHECK-LABEL:   func.func @_QPtest2(
76 // CHECK:           fir.do_loop %[[VAL_11:.*]] =
77 // CHECK:             fir.do_loop %[[VAL_12:.*]] =
78 // CHECK:               %[[VAL_13:.*]] = hlfir.designate %[[VAL_9:.*]] (%[[VAL_12]], %[[VAL_11]])  : (!fir.box<!fir.array<7998x120xf32>>, index, index) -> !fir.ref<f32>
79 // CHECK:               %[[VAL_14:.*]] = fir.load %[[VAL_13]] : !fir.ref<f32>
80 // CHECK:               %[[VAL_15:.*]] = hlfir.no_reassoc %[[VAL_14]] : f32
81 // CHECK:               %[[VAL_16:.*]] = hlfir.designate %[[VAL_10:.*]] (%[[VAL_12]], %[[VAL_11]])  : (!fir.box<!fir.array<7998x120xf32>>, index, index) -> !fir.ref<f32>
82 // CHECK:               hlfir.assign %[[VAL_15]] to %[[VAL_16]] : f32, !fir.ref<f32>
83 // CHECK:             }
84 // CHECK:           }
86 func.func @_QPtest3(%arg0: !fir.ref<!fir.array<10x!fir.type<_QMtypesTt{x:!fir.array<8000x120x3xf32>}>>> {fir.bindc_name = "x"}) {
87   %c7998 = arith.constant 7998 : index
88   %c7999 = arith.constant 7999 : index
89   %c2 = arith.constant 2 : index
90   %c3 = arith.constant 3 : index
91   %c120 = arith.constant 120 : index
92   %c8000 = arith.constant 8000 : index
93   %c1 = arith.constant 1 : index
94   %c10 = arith.constant 10 : index
95   %0 = fir.alloca i32 {bindc_name = "new", uniq_name = "_QFtest3Enew"}
96   %1:2 = hlfir.declare %0 {uniq_name = "_QFtest3Enew"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
97   %2 = fir.alloca i32 {bindc_name = "old", uniq_name = "_QFtest3Eold"}
98   %3:2 = hlfir.declare %2 {uniq_name = "_QFtest3Eold"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
99   %4 = fir.shape %c10 : (index) -> !fir.shape<1>
100   %5:2 = hlfir.declare %arg0(%4) {uniq_name = "_QFtest3Ex"} : (!fir.ref<!fir.array<10x!fir.type<_QMtypesTt{x:!fir.array<8000x120x3xf32>}>>>, !fir.shape<1>) -> (!fir.ref<!fir.array<10x!fir.type<_QMtypesTt{x:!fir.array<8000x120x3xf32>}>>>, !fir.ref<!fir.array<10x!fir.type<_QMtypesTt{x:!fir.array<8000x120x3xf32>}>>>)
101   %6 = hlfir.designate %5#0 (%c1)  : (!fir.ref<!fir.array<10x!fir.type<_QMtypesTt{x:!fir.array<8000x120x3xf32>}>>>, index) -> !fir.ref<!fir.type<_QMtypesTt{x:!fir.array<8000x120x3xf32>}>>
102   %7 = fir.shape %c8000, %c120, %c3 : (index, index, index) -> !fir.shape<3>
103   %8 = fir.load %3#0 : !fir.ref<i32>
104   %9 = fir.convert %8 : (i32) -> i64
105   %10 = fir.shape %c7998, %c120 : (index, index) -> !fir.shape<2>
106   %11 = hlfir.designate %6{"x"} <%7> (%c2:%c7999:%c1, %c1:%c120:%c1, %9)  shape %10 : (!fir.ref<!fir.type<_QMtypesTt{x:!fir.array<8000x120x3xf32>}>>, !fir.shape<3>, index, index, index, index, index, index, i64, !fir.shape<2>) -> !fir.box<!fir.array<7998x120xf32>>
107   %12 = hlfir.elemental %10 unordered : (!fir.shape<2>) -> !hlfir.expr<7998x120xf32> {
108   ^bb0(%arg1: index, %arg2: index):
109     %16 = hlfir.designate %11 (%arg1, %arg2)  : (!fir.box<!fir.array<7998x120xf32>>, index, index) -> !fir.ref<f32>
110     %17 = fir.load %16 : !fir.ref<f32>
111     %18 = hlfir.no_reassoc %17 : f32
112     hlfir.yield_element %18 : f32
113   }
114   %13 = fir.load %1#0 : !fir.ref<i32>
115   %14 = fir.convert %13 : (i32) -> i64
116   %15 = hlfir.designate %6{"x"} <%7> (%c2:%c7999:%c1, %c1:%c120:%c1, %14)  shape %10 : (!fir.ref<!fir.type<_QMtypesTt{x:!fir.array<8000x120x3xf32>}>>, !fir.shape<3>, index, index, index, index, index, index, i64, !fir.shape<2>) -> !fir.box<!fir.array<7998x120xf32>>
117   hlfir.assign %12 to %15 : !hlfir.expr<7998x120xf32>, !fir.box<!fir.array<7998x120xf32>>
118   hlfir.destroy %12 : !hlfir.expr<7998x120xf32>
119   return
121 // CHECK-LABEL:   func.func @_QPtest3(
122 // CHECK:           fir.do_loop %[[VAL_24:.*]] =
123 // CHECK:             fir.do_loop %[[VAL_25:.*]] =
124 // CHECK:               %[[VAL_26:.*]] = hlfir.designate %[[VAL_20:.*]] (%[[VAL_25]], %[[VAL_24]])  : (!fir.box<!fir.array<7998x120xf32>>, index, index) -> !fir.ref<f32>
125 // CHECK:               %[[VAL_27:.*]] = fir.load %[[VAL_26]] : !fir.ref<f32>
126 // CHECK:               %[[VAL_28:.*]] = hlfir.no_reassoc %[[VAL_27]] : f32
127 // CHECK:               %[[VAL_29:.*]] = hlfir.designate %[[VAL_23:.*]] (%[[VAL_25]], %[[VAL_24]])  : (!fir.box<!fir.array<7998x120xf32>>, index, index) -> !fir.ref<f32>
128 // CHECK:               hlfir.assign %[[VAL_28]] to %[[VAL_29]] : f32, !fir.ref<f32>
129 // CHECK:             }
130 // CHECK:           }
132 // ! ub == lb - 1
133 // subroutine test4(x, i1, i2, nx)
134 //   real :: x(i2), f
135 //   do i=i1,i2,nx
136 //      x(i:i+nx-1) = (x(i-nx:i-1))
137 //   end do
138 // end subroutine test4
139 func.func @_QPtest4(%arg0: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "x"}, %arg1: !fir.ref<i32> {fir.bindc_name = "i1"}, %arg2: !fir.ref<i32> {fir.bindc_name = "i2"}, %arg3: !fir.ref<i32> {fir.bindc_name = "nx"}) {
140   %c1 = arith.constant 1 : index
141   %c1_i32 = arith.constant 1 : i32
142   %c0 = arith.constant 0 : index
143   %0 = fir.alloca f32 {bindc_name = "f", uniq_name = "_QFtest4Ef"}
144   %1:2 = hlfir.declare %0 {uniq_name = "_QFtest4Ef"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
145   %2 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFtest4Ei"}
146   %3:2 = hlfir.declare %2 {uniq_name = "_QFtest4Ei"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
147   %4:2 = hlfir.declare %arg1 {uniq_name = "_QFtest4Ei1"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
148   %5:2 = hlfir.declare %arg2 {uniq_name = "_QFtest4Ei2"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
149   %6:2 = hlfir.declare %arg3 {uniq_name = "_QFtest4Enx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
150   %7 = fir.load %5#0 : !fir.ref<i32>
151   %8 = fir.convert %7 : (i32) -> index
152   %9 = arith.cmpi sgt, %8, %c0 : index
153   %10 = arith.select %9, %8, %c0 : index
154   %11 = fir.shape %10 : (index) -> !fir.shape<1>
155   %12:2 = hlfir.declare %arg0(%11) {uniq_name = "_QFtest4Ex"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>)
156   %13 = fir.load %4#0 : !fir.ref<i32>
157   %14 = fir.convert %13 : (i32) -> index
158   %15 = fir.load %5#0 : !fir.ref<i32>
159   %16 = fir.convert %15 : (i32) -> index
160   %17 = fir.load %6#0 : !fir.ref<i32>
161   %18 = fir.convert %17 : (i32) -> index
162   %19 = fir.convert %14 : (index) -> i32
163   %20:2 = fir.do_loop %arg4 = %14 to %16 step %18 iter_args(%arg5 = %19) -> (index, i32) {
164     fir.store %arg5 to %3#1 : !fir.ref<i32>
165     %21 = fir.load %3#0 : !fir.ref<i32>
166     %22 = fir.load %6#0 : !fir.ref<i32>
167     %23 = arith.subi %21, %22 : i32
168     %24 = arith.subi %21, %c1_i32 : i32
169     %25 = fir.convert %23 : (i32) -> index
170     %26 = fir.convert %24 : (i32) -> index
171     %27 = arith.subi %26, %25 : index
172     %28 = arith.addi %27, %c1 : index
173     %29 = arith.cmpi sgt, %28, %c0 : index
174     %30 = arith.select %29, %28, %c0 : index
175     %31 = fir.shape %30 : (index) -> !fir.shape<1>
176     %32 = hlfir.designate %12#0 (%25:%26:%c1)  shape %31 : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
177     %33 = hlfir.elemental %31 unordered : (!fir.shape<1>) -> !hlfir.expr<?xf32> {
178     ^bb0(%arg6: index):
179       %48 = hlfir.designate %32 (%arg6)  : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32>
180       %49 = fir.load %48 : !fir.ref<f32>
181       %50 = hlfir.no_reassoc %49 : f32
182       hlfir.yield_element %50 : f32
183     }
184     %34 = arith.addi %21, %22 : i32
185     %35 = arith.subi %34, %c1_i32 : i32
186     %36 = fir.convert %21 : (i32) -> index
187     %37 = fir.convert %35 : (i32) -> index
188     %38 = arith.subi %37, %36 : index
189     %39 = arith.addi %38, %c1 : index
190     %40 = arith.cmpi sgt, %39, %c0 : index
191     %41 = arith.select %40, %39, %c0 : index
192     %42 = fir.shape %41 : (index) -> !fir.shape<1>
193     %43 = hlfir.designate %12#0 (%36:%37:%c1)  shape %42 : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
194     hlfir.assign %33 to %43 : !hlfir.expr<?xf32>, !fir.box<!fir.array<?xf32>>
195     hlfir.destroy %33 : !hlfir.expr<?xf32>
196     %44 = arith.addi %arg4, %18 : index
197     %45 = fir.convert %18 : (index) -> i32
198     %46 = fir.load %3#1 : !fir.ref<i32>
199     %47 = arith.addi %46, %45 : i32
200     fir.result %44, %47 : index, i32
201   }
202   fir.store %20#1 to %3#1 : !fir.ref<i32>
203   return
205 // CHECK-LABEL:   func.func @_QPtest4(
206 // CHECK-NOT: hlfir.elemental
208 // ! lb == ub + 1
209 // subroutine test5(x, i1, i2, nx)
210 //   real :: x(i2), f
211 //   do i=i1,i2,nx
212 //      x(i+1:i+nx-1) = (x(i-nx:i))
213 //   end do
214 // end subroutine test5
215 func.func @_QPtest5(%arg0: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "x"}, %arg1: !fir.ref<i32> {fir.bindc_name = "i1"}, %arg2: !fir.ref<i32> {fir.bindc_name = "i2"}, %arg3: !fir.ref<i32> {fir.bindc_name = "nx"}) {
216   %c1_i32 = arith.constant 1 : i32
217   %c1 = arith.constant 1 : index
218   %c0 = arith.constant 0 : index
219   %0 = fir.alloca f32 {bindc_name = "f", uniq_name = "_QFtest5Ef"}
220   %1:2 = hlfir.declare %0 {uniq_name = "_QFtest5Ef"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
221   %2 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFtest5Ei"}
222   %3:2 = hlfir.declare %2 {uniq_name = "_QFtest5Ei"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
223   %4:2 = hlfir.declare %arg1 {uniq_name = "_QFtest5Ei1"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
224   %5:2 = hlfir.declare %arg2 {uniq_name = "_QFtest5Ei2"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
225   %6:2 = hlfir.declare %arg3 {uniq_name = "_QFtest5Enx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
226   %7 = fir.load %5#0 : !fir.ref<i32>
227   %8 = fir.convert %7 : (i32) -> index
228   %9 = arith.cmpi sgt, %8, %c0 : index
229   %10 = arith.select %9, %8, %c0 : index
230   %11 = fir.shape %10 : (index) -> !fir.shape<1>
231   %12:2 = hlfir.declare %arg0(%11) {uniq_name = "_QFtest5Ex"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>)
232   %13 = fir.load %4#0 : !fir.ref<i32>
233   %14 = fir.convert %13 : (i32) -> index
234   %15 = fir.load %5#0 : !fir.ref<i32>
235   %16 = fir.convert %15 : (i32) -> index
236   %17 = fir.load %6#0 : !fir.ref<i32>
237   %18 = fir.convert %17 : (i32) -> index
238   %19 = fir.convert %14 : (index) -> i32
239   %20:2 = fir.do_loop %arg4 = %14 to %16 step %18 iter_args(%arg5 = %19) -> (index, i32) {
240     fir.store %arg5 to %3#1 : !fir.ref<i32>
241     %21 = fir.load %3#0 : !fir.ref<i32>
242     %22 = fir.load %6#0 : !fir.ref<i32>
243     %23 = arith.subi %21, %22 : i32
244     %24 = fir.convert %23 : (i32) -> index
245     %25 = fir.convert %21 : (i32) -> index
246     %26 = arith.subi %25, %24 : index
247     %27 = arith.addi %26, %c1 : index
248     %28 = arith.cmpi sgt, %27, %c0 : index
249     %29 = arith.select %28, %27, %c0 : index
250     %30 = fir.shape %29 : (index) -> !fir.shape<1>
251     %31 = hlfir.designate %12#0 (%24:%25:%c1)  shape %30 : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
252     %32 = hlfir.elemental %30 unordered : (!fir.shape<1>) -> !hlfir.expr<?xf32> {
253     ^bb0(%arg6: index):
254       %48 = hlfir.designate %31 (%arg6)  : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32>
255       %49 = fir.load %48 : !fir.ref<f32>
256       %50 = hlfir.no_reassoc %49 : f32
257       hlfir.yield_element %50 : f32
258     }
259     %33 = arith.addi %21, %c1_i32 : i32
260     %34 = arith.addi %21, %22 : i32
261     %35 = arith.subi %34, %c1_i32 : i32
262     %36 = fir.convert %33 : (i32) -> index
263     %37 = fir.convert %35 : (i32) -> index
264     %38 = arith.subi %37, %36 : index
265     %39 = arith.addi %38, %c1 : index
266     %40 = arith.cmpi sgt, %39, %c0 : index
267     %41 = arith.select %40, %39, %c0 : index
268     %42 = fir.shape %41 : (index) -> !fir.shape<1>
269     %43 = hlfir.designate %12#0 (%36:%37:%c1)  shape %42 : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
270     hlfir.assign %32 to %43 : !hlfir.expr<?xf32>, !fir.box<!fir.array<?xf32>>
271     hlfir.destroy %32 : !hlfir.expr<?xf32>
272     %44 = arith.addi %arg4, %18 : index
273     %45 = fir.convert %18 : (index) -> i32
274     %46 = fir.load %3#1 : !fir.ref<i32>
275     %47 = arith.addi %46, %45 : i32
276     fir.result %44, %47 : index, i32
277   }
278   fir.store %20#1 to %3#1 : !fir.ref<i32>
279   return
281 // CHECK-LABEL:   func.func @_QPtest5(
282 // CHECK-NOT: hlfir.elemental
284 // ! ub = lb - 1 and dim1 is unknown
285 // ! FIR lowering produces a temp.
286 // subroutine test6(x, i1, i2, nx)
287 //   real :: x(i2,i2), f
288 //   integer n1, n2, n3, n4
289 //   do i=i1,i2,nx
290 //      x(i:i+nx-1,n1:n2) = (x(i-nx:i-1,n3:n4))
291 //   end do
292 // end subroutine test6
293 func.func @_QPtest6(%arg0: !fir.ref<!fir.array<?x?xf32>> {fir.bindc_name = "x"}, %arg1: !fir.ref<i32> {fir.bindc_name = "i1"}, %arg2: !fir.ref<i32> {fir.bindc_name = "i2"}, %arg3: !fir.ref<i32> {fir.bindc_name = "nx"}) {
294   %c1 = arith.constant 1 : index
295   %c1_i32 = arith.constant 1 : i32
296   %c0 = arith.constant 0 : index
297   %0 = fir.alloca f32 {bindc_name = "f", uniq_name = "_QFtest6Ef"}
298   %1:2 = hlfir.declare %0 {uniq_name = "_QFtest6Ef"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
299   %2 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFtest6Ei"}
300   %3:2 = hlfir.declare %2 {uniq_name = "_QFtest6Ei"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
301   %4:2 = hlfir.declare %arg1 {uniq_name = "_QFtest6Ei1"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
302   %5:2 = hlfir.declare %arg2 {uniq_name = "_QFtest6Ei2"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
303   %6 = fir.alloca i32 {bindc_name = "n1", uniq_name = "_QFtest6En1"}
304   %7:2 = hlfir.declare %6 {uniq_name = "_QFtest6En1"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
305   %8 = fir.alloca i32 {bindc_name = "n2", uniq_name = "_QFtest6En2"}
306   %9:2 = hlfir.declare %8 {uniq_name = "_QFtest6En2"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
307   %10 = fir.alloca i32 {bindc_name = "n3", uniq_name = "_QFtest6En3"}
308   %11:2 = hlfir.declare %10 {uniq_name = "_QFtest6En3"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
309   %12 = fir.alloca i32 {bindc_name = "n4", uniq_name = "_QFtest6En4"}
310   %13:2 = hlfir.declare %12 {uniq_name = "_QFtest6En4"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
311   %14:2 = hlfir.declare %arg3 {uniq_name = "_QFtest6Enx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
312   %15 = fir.load %5#0 : !fir.ref<i32>
313   %16 = fir.convert %15 : (i32) -> index
314   %17 = arith.cmpi sgt, %16, %c0 : index
315   %18 = arith.select %17, %16, %c0 : index
316   %19 = fir.shape %18, %18 : (index, index) -> !fir.shape<2>
317   %20:2 = hlfir.declare %arg0(%19) {uniq_name = "_QFtest6Ex"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.ref<!fir.array<?x?xf32>>)
318   %21 = fir.load %4#0 : !fir.ref<i32>
319   %22 = fir.convert %21 : (i32) -> index
320   %23 = fir.load %5#0 : !fir.ref<i32>
321   %24 = fir.convert %23 : (i32) -> index
322   %25 = fir.load %14#0 : !fir.ref<i32>
323   %26 = fir.convert %25 : (i32) -> index
324   %27 = fir.convert %22 : (index) -> i32
325   %28:2 = fir.do_loop %arg4 = %22 to %24 step %26 iter_args(%arg5 = %27) -> (index, i32) {
326     fir.store %arg5 to %3#1 : !fir.ref<i32>
327     %29 = fir.load %3#0 : !fir.ref<i32>
328     %30 = fir.load %14#0 : !fir.ref<i32>
329     %31 = arith.subi %29, %30 : i32
330     %32 = arith.subi %29, %c1_i32 : i32
331     %33 = fir.convert %31 : (i32) -> index
332     %34 = fir.convert %32 : (i32) -> index
333     %35 = arith.subi %34, %33 : index
334     %36 = arith.addi %35, %c1 : index
335     %37 = arith.cmpi sgt, %36, %c0 : index
336     %38 = arith.select %37, %36, %c0 : index
337     %39 = fir.load %11#0 : !fir.ref<i32>
338     %40 = fir.load %13#0 : !fir.ref<i32>
339     %41 = fir.convert %39 : (i32) -> index
340     %42 = fir.convert %40 : (i32) -> index
341     %43 = arith.subi %42, %41 : index
342     %44 = arith.addi %43, %c1 : index
343     %45 = arith.cmpi sgt, %44, %c0 : index
344     %46 = arith.select %45, %44, %c0 : index
345     %47 = fir.shape %38, %46 : (index, index) -> !fir.shape<2>
346     %48 = hlfir.designate %20#0 (%33:%34:%c1, %41:%42:%c1)  shape %47 : (!fir.box<!fir.array<?x?xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>>
347     %49 = hlfir.elemental %47 unordered : (!fir.shape<2>) -> !hlfir.expr<?x?xf32> {
348     ^bb0(%arg6: index, %arg7: index):
349       %72 = hlfir.designate %48 (%arg6, %arg7)  : (!fir.box<!fir.array<?x?xf32>>, index, index) -> !fir.ref<f32>
350       %73 = fir.load %72 : !fir.ref<f32>
351       %74 = hlfir.no_reassoc %73 : f32
352       hlfir.yield_element %74 : f32
353     }
354     %50 = arith.addi %29, %30 : i32
355     %51 = arith.subi %50, %c1_i32 : i32
356     %52 = fir.convert %29 : (i32) -> index
357     %53 = fir.convert %51 : (i32) -> index
358     %54 = arith.subi %53, %52 : index
359     %55 = arith.addi %54, %c1 : index
360     %56 = arith.cmpi sgt, %55, %c0 : index
361     %57 = arith.select %56, %55, %c0 : index
362     %58 = fir.load %7#0 : !fir.ref<i32>
363     %59 = fir.load %9#0 : !fir.ref<i32>
364     %60 = fir.convert %58 : (i32) -> index
365     %61 = fir.convert %59 : (i32) -> index
366     %62 = arith.subi %61, %60 : index
367     %63 = arith.addi %62, %c1 : index
368     %64 = arith.cmpi sgt, %63, %c0 : index
369     %65 = arith.select %64, %63, %c0 : index
370     %66 = fir.shape %57, %65 : (index, index) -> !fir.shape<2>
371     %67 = hlfir.designate %20#0 (%52:%53:%c1, %60:%61:%c1)  shape %66 : (!fir.box<!fir.array<?x?xf32>>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>>
372     hlfir.assign %49 to %67 : !hlfir.expr<?x?xf32>, !fir.box<!fir.array<?x?xf32>>
373     hlfir.destroy %49 : !hlfir.expr<?x?xf32>
374     %68 = arith.addi %arg4, %26 : index
375     %69 = fir.convert %26 : (index) -> i32
376     %70 = fir.load %3#1 : !fir.ref<i32>
377     %71 = arith.addi %70, %69 : i32
378     fir.result %68, %71 : index, i32
379   }
380   fir.store %28#1 to %3#1 : !fir.ref<i32>
381   return
383 // CHECK-LABEL:   func.func @_QPtest6(
384 // CHECK-NOT: hlfir.elemental