Debian Codegraph @

flang/test/Transforms/optimize-array-repacking.fir

raw
1 // Test that the redundant fir.[un]pack_array operations
2 // are optimized away, when the source is statically known
3 // to be contiguous.
4 // RUN: fir-opt --optimize-array-repacking %s | FileCheck %s
5
6 // FIR is produced by compiling the sources with -mllvm -inline-all.
7 // module inner
8 // contains
9 // subroutine inner_repack1(x)
10 // real :: x(:)
11 // end subroutine inner_repack1
12 // subroutine inner_repack2(x)
13 // real :: x(:,:)
14 // end subroutine inner_repack2
15 // end module inner
16
17 // subroutine test_explicit_shape_cst(x)
18 // real :: x(100)
19 // call repack(x(1:50))
20 // contains
21 // subroutine repack(x)
22 // real :: x(:)
23 // end subroutine repack
24 // end subroutine test_explicit_shape_cst
25 //
26 // CHECK-LABEL: func.func @_QPtest_explicit_shape_cst(
27 // CHECK-NOT: fir.{{.*}}pack_array
28 func.func @_QPtest_explicit_shape_cst(%arg0: !fir.ref<!fir.array<100xf32>> {fir.bindc_name = "x"}) {
29 %c50 = arith.constant 50 : index
30 %c1 = arith.constant 1 : index
31 %c100 = arith.constant 100 : index
32 %0 = fir.dummy_scope : !fir.dscope
33 %1 = fir.shape %c100 : (index) -> !fir.shape<1>
34 %2 = fir.declare %arg0(%1) dummy_scope %0 {uniq_name = "_QFtest_explicit_shape_cstEx"} : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, !fir.dscope) -> !fir.ref<!fir.array<100xf32>>
35 %3 = fir.shape %c50 : (index) -> !fir.shape<1>
36 %4 = fir.array_coor %2(%1) %c1 : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>
37 %5 = fir.convert %4 : (!fir.ref<f32>) -> !fir.ref<!fir.array<50xf32>>
38 %6 = fir.embox %5(%3) : (!fir.ref<!fir.array<50xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<50xf32>>
39 %7 = fir.convert %6 : (!fir.box<!fir.array<50xf32>>) -> !fir.box<!fir.array<?xf32>>
40 %8 = fir.dummy_scope : !fir.dscope
41 %9 = fir.pack_array %7 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
42 %10 = fir.declare %9 dummy_scope %8 {uniq_name = "_QFtest_explicit_shape_cstFrepackEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
43 fir.unpack_array %9 to %7 heap : !fir.box<!fir.array<?xf32>>
44 return
45 }
46
47 // subroutine test_explicit_shape_var(x, n, l, u)
48 // integer :: n, l, u
49 // real :: x(n)
50 // call repack(x(l:u))
51 // contains
52 // subroutine repack(x)
53 // real :: x(:)
54 // end subroutine repack
55 // end subroutine test_explicit_shape_var
56 //
57 // CHECK-LABEL: func.func @_QPtest_explicit_shape_var(
58 // CHECK-NOT: fir.{{.*}}pack_array
59 func.func @_QPtest_explicit_shape_var(%arg0: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "x"}, %arg1: !fir.ref<i32> {fir.bindc_name = "n"}, %arg2: !fir.ref<i32> {fir.bindc_name = "l"}, %arg3: !fir.ref<i32> {fir.bindc_name = "u"}) {
60 %c1 = arith.constant 1 : index
61 %c0 = arith.constant 0 : index
62 %0 = fir.dummy_scope : !fir.dscope
63 %1 = fir.declare %arg2 dummy_scope %0 {uniq_name = "_QFtest_explicit_shape_varEl"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
64 %2 = fir.declare %arg1 dummy_scope %0 {uniq_name = "_QFtest_explicit_shape_varEn"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
65 %3 = fir.declare %arg3 dummy_scope %0 {uniq_name = "_QFtest_explicit_shape_varEu"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
66 %4 = fir.load %2 : !fir.ref<i32>
67 %5 = fir.convert %4 : (i32) -> index
68 %6 = arith.cmpi sgt, %5, %c0 : index
69 %7 = arith.select %6, %5, %c0 : index
70 %8 = fir.shape %7 : (index) -> !fir.shape<1>
71 %9 = fir.declare %arg0(%8) dummy_scope %0 {uniq_name = "_QFtest_explicit_shape_varEx"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, !fir.dscope) -> !fir.ref<!fir.array<?xf32>>
72 %10 = fir.load %1 : !fir.ref<i32>
73 %11 = fir.load %3 : !fir.ref<i32>
74 %12 = fir.convert %10 : (i32) -> index
75 %13 = fir.convert %11 : (i32) -> index
76 %14 = fir.slice %12, %13, %c1 : (index, index, index) -> !fir.slice<1>
77 %15 = fir.embox %9(%8) [%14] : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
78 %16 = fir.dummy_scope : !fir.dscope
79 %17 = fir.pack_array %15 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
80 %18 = fir.declare %17 dummy_scope %16 {uniq_name = "_QFtest_explicit_shape_varFrepackEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
81 fir.unpack_array %17 to %15 heap : !fir.box<!fir.array<?xf32>>
82 return
83 }
84
85 // subroutine test_assumed_size_cst(x)
86 // real :: x(*)
87 // call repack(x(1:50))
88 // contains
89 // subroutine repack(x)
90 // real :: x(:)
91 // end subroutine repack
92 // end subroutine test_assumed_size_cst
93 //
94 // CHECK-LABEL: func.func @_QPtest_assumed_size_cst(
95 // CHECK-NOT: fir.{{.*}}pack_array
96 func.func @_QPtest_assumed_size_cst(%arg0: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "x"}) {
97 %c50 = arith.constant 50 : index
98 %c1 = arith.constant 1 : index
99 %c-1 = arith.constant -1 : index
100 %0 = fir.dummy_scope : !fir.dscope
101 %1 = fir.shape %c-1 : (index) -> !fir.shape<1>
102 %2 = fir.declare %arg0(%1) dummy_scope %0 {uniq_name = "_QFtest_assumed_size_cstEx"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, !fir.dscope) -> !fir.ref<!fir.array<?xf32>>
103 %3 = fir.shape %c50 : (index) -> !fir.shape<1>
104 %4 = fir.array_coor %2(%1) %c1 : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>
105 %5 = fir.convert %4 : (!fir.ref<f32>) -> !fir.ref<!fir.array<50xf32>>
106 %6 = fir.embox %5(%3) : (!fir.ref<!fir.array<50xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<50xf32>>
107 %7 = fir.convert %6 : (!fir.box<!fir.array<50xf32>>) -> !fir.box<!fir.array<?xf32>>
108 %8 = fir.dummy_scope : !fir.dscope
109 %9 = fir.pack_array %7 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
110 %10 = fir.declare %9 dummy_scope %8 {uniq_name = "_QFtest_assumed_size_cstFrepackEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
111 fir.unpack_array %9 to %7 heap : !fir.box<!fir.array<?xf32>>
112 return
113 }
114
115 // subroutine test_assumed_size_var(x, l, u)
116 // integer :: l, u
117 // real :: x(*)
118 // call repack(x(l:u))
119 // contains
120 // subroutine repack(x)
121 // real :: x(:)
122 // end subroutine repack
123 // end subroutine test_assumed_size_var
124 //
125 // CHECK-LABEL: func.func @_QPtest_assumed_size_var(
126 // CHECK-NOT: fir.{{.*}}pack_array
127 func.func @_QPtest_assumed_size_var(%arg0: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "x"}, %arg1: !fir.ref<i32> {fir.bindc_name = "l"}, %arg2: !fir.ref<i32> {fir.bindc_name = "u"}) {
128 %c1 = arith.constant 1 : index
129 %c-1 = arith.constant -1 : index
130 %0 = fir.dummy_scope : !fir.dscope
131 %1 = fir.declare %arg1 dummy_scope %0 {uniq_name = "_QFtest_assumed_size_varEl"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
132 %2 = fir.declare %arg2 dummy_scope %0 {uniq_name = "_QFtest_assumed_size_varEu"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
133 %3 = fir.shape %c-1 : (index) -> !fir.shape<1>
134 %4 = fir.declare %arg0(%3) dummy_scope %0 {uniq_name = "_QFtest_assumed_size_varEx"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, !fir.dscope) -> !fir.ref<!fir.array<?xf32>>
135 %5 = fir.load %1 : !fir.ref<i32>
136 %6 = fir.load %2 : !fir.ref<i32>
137 %7 = fir.convert %5 : (i32) -> index
138 %8 = fir.convert %6 : (i32) -> index
139 %9 = fir.slice %7, %8, %c1 : (index, index, index) -> !fir.slice<1>
140 %10 = fir.embox %4(%3) [%9] : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
141 %11 = fir.dummy_scope : !fir.dscope
142 %12 = fir.pack_array %10 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
143 %13 = fir.declare %12 dummy_scope %11 {uniq_name = "_QFtest_assumed_size_varFrepackEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
144 fir.unpack_array %12 to %10 heap : !fir.box<!fir.array<?xf32>>
145 return
146 }
147
148 // subroutine test_allocatable_cst(x)
149 // real, allocatable :: x(:)
150 // call repack(x(10:50))
151 // contains
152 // subroutine repack(x)
153 // real :: x(:)
154 // end subroutine repack
155 // end subroutine test_allocatable_cst
156 //
157 // CHECK-LABEL: func.func @_QPtest_allocatable_cst(
158 // CHECK-NOT: fir.{{.*}}pack_array
159 func.func @_QPtest_allocatable_cst(%arg0: !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> {fir.bindc_name = "x"}) {
160 %c0 = arith.constant 0 : index
161 %c41 = arith.constant 41 : index
162 %c10 = arith.constant 10 : index
163 %0 = fir.dummy_scope : !fir.dscope
164 %1 = fir.declare %arg0 dummy_scope %0 {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest_allocatable_cstEx"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>, !fir.dscope) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
165 %2 = fir.load %1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
166 %3 = fir.shape %c41 : (index) -> !fir.shape<1>
167 %4 = fir.box_addr %2 : (!fir.box<!fir.heap<!fir.array<?xf32>>>) -> !fir.heap<!fir.array<?xf32>>
168 %5:3 = fir.box_dims %2, %c0 : (!fir.box<!fir.heap<!fir.array<?xf32>>>, index) -> (index, index, index)
169 %6 = fir.shape_shift %5#0, %5#1 : (index, index) -> !fir.shapeshift<1>
170 %7 = fir.array_coor %4(%6) %c10 : (!fir.heap<!fir.array<?xf32>>, !fir.shapeshift<1>, index) -> !fir.ref<f32>
171 %8 = fir.convert %7 : (!fir.ref<f32>) -> !fir.ref<!fir.array<41xf32>>
172 %9 = fir.embox %8(%3) : (!fir.ref<!fir.array<41xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<41xf32>>
173 %10 = fir.convert %9 : (!fir.box<!fir.array<41xf32>>) -> !fir.box<!fir.array<?xf32>>
174 %11 = fir.dummy_scope : !fir.dscope
175 %12 = fir.pack_array %10 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
176 %13 = fir.declare %12 dummy_scope %11 {uniq_name = "_QFtest_allocatable_cstFrepackEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
177 fir.unpack_array %12 to %10 heap : !fir.box<!fir.array<?xf32>>
178 return
179 }
180
181 // subroutine test_allocatable_var(x, l, u)
182 // integer :: l, u
183 // real, allocatable :: x(:)
184 // call repack(x(l:u))
185 // contains
186 // subroutine repack(x)
187 // real :: x(:)
188 // end subroutine repack
189 // end subroutine test_allocatable_var
190 //
191 // CHECK-LABEL: func.func @_QPtest_allocatable_var(
192 // CHECK-NOT: fir.{{.*}}pack_array
193 func.func @_QPtest_allocatable_var(%arg0: !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> {fir.bindc_name = "x"}, %arg1: !fir.ref<i32> {fir.bindc_name = "l"}, %arg2: !fir.ref<i32> {fir.bindc_name = "u"}) {
194 %c0 = arith.constant 0 : index
195 %c1 = arith.constant 1 : index
196 %0 = fir.dummy_scope : !fir.dscope
197 %1 = fir.declare %arg1 dummy_scope %0 {uniq_name = "_QFtest_allocatable_varEl"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
198 %2 = fir.declare %arg2 dummy_scope %0 {uniq_name = "_QFtest_allocatable_varEu"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
199 %3 = fir.declare %arg0 dummy_scope %0 {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest_allocatable_varEx"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>, !fir.dscope) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
200 %4 = fir.load %3 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
201 %5 = fir.load %1 : !fir.ref<i32>
202 %6 = fir.load %2 : !fir.ref<i32>
203 %7 = fir.convert %5 : (i32) -> index
204 %8 = fir.convert %6 : (i32) -> index
205 %9 = fir.box_addr %4 : (!fir.box<!fir.heap<!fir.array<?xf32>>>) -> !fir.heap<!fir.array<?xf32>>
206 %10:3 = fir.box_dims %4, %c0 : (!fir.box<!fir.heap<!fir.array<?xf32>>>, index) -> (index, index, index)
207 %11 = fir.shape_shift %10#0, %10#1 : (index, index) -> !fir.shapeshift<1>
208 %12 = fir.slice %7, %8, %c1 : (index, index, index) -> !fir.slice<1>
209 %13 = fir.embox %9(%11) [%12] : (!fir.heap<!fir.array<?xf32>>, !fir.shapeshift<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
210 %14 = fir.dummy_scope : !fir.dscope
211 %15 = fir.pack_array %13 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
212 %16 = fir.declare %15 dummy_scope %14 {uniq_name = "_QFtest_allocatable_varFrepackEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
213 fir.unpack_array %15 to %13 heap : !fir.box<!fir.array<?xf32>>
214 return
215 }
216
217 // subroutine test_allocatable_full(x)
218 // real, allocatable :: x(:,:)
219 // call repack(x(:,:))
220 // contains
221 // subroutine repack(x)
222 // real :: x(:,:)
223 // end subroutine repack
224 // end subroutine test_allocatable_full
225 //
226 // CHECK-LABEL: func.func @_QPtest_allocatable_full(
227 // CHECK-NOT: fir.{{.*}}pack_array
228 func.func @_QPtest_allocatable_full(%arg0: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>> {fir.bindc_name = "x"}) {
229 %c1 = arith.constant 1 : index
230 %c0 = arith.constant 0 : index
231 %0 = fir.dummy_scope : !fir.dscope
232 %1 = fir.declare %arg0 dummy_scope %0 {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest_allocatable_fullEx"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>, !fir.dscope) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>
233 %2 = fir.load %1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>
234 %3:3 = fir.box_dims %2, %c0 : (!fir.box<!fir.heap<!fir.array<?x?xf32>>>, index) -> (index, index, index)
235 %4:3 = fir.box_dims %2, %c1 : (!fir.box<!fir.heap<!fir.array<?x?xf32>>>, index) -> (index, index, index)
236 %5 = arith.addi %3#0, %3#1 : index
237 %6 = arith.subi %5, %c1 : index
238 %7 = arith.addi %4#0, %4#1 : index
239 %8 = arith.subi %7, %c1 : index
240 %9 = fir.box_addr %2 : (!fir.box<!fir.heap<!fir.array<?x?xf32>>>) -> !fir.heap<!fir.array<?x?xf32>>
241 %10 = fir.shape_shift %3#0, %3#1, %4#0, %4#1 : (index, index, index, index) -> !fir.shapeshift<2>
242 %11 = fir.slice %3#0, %6, %c1, %4#0, %8, %c1 : (index, index, index, index, index, index) -> !fir.slice<2>
243 %12 = fir.embox %9(%10) [%11] : (!fir.heap<!fir.array<?x?xf32>>, !fir.shapeshift<2>, !fir.slice<2>) -> !fir.box<!fir.array<?x?xf32>>
244 %13 = fir.dummy_scope : !fir.dscope
245 %14 = fir.pack_array %12 heap innermost : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<!fir.array<?x?xf32>>
246 %15 = fir.declare %14 dummy_scope %13 {uniq_name = "_QFtest_allocatable_fullFrepackEx"} : (!fir.box<!fir.array<?x?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?x?xf32>>
247 fir.unpack_array %14 to %12 heap : !fir.box<!fir.array<?x?xf32>>
248 return
249 }
250
251 // subroutine test_explicit_shape_cst_chain(x)
252 // real :: x(100)
253 // call repack(x(1:50))
254 // contains
255 // subroutine repack(x)
256 // use inner
257 // real :: x(:)
258 // call inner_repack1(x)
259 // end subroutine repack
260 // end subroutine test_explicit_shape_cst_chain
261 //
262 // CHECK-LABEL: func.func @_QPtest_explicit_shape_cst_chain(
263 // CHECK-NOT: fir.{{.*}}pack_array
264 func.func @_QPtest_explicit_shape_cst_chain(%arg0: !fir.ref<!fir.array<100xf32>> {fir.bindc_name = "x"}) {
265 %c50 = arith.constant 50 : index
266 %c1 = arith.constant 1 : index
267 %c100 = arith.constant 100 : index
268 %0 = fir.dummy_scope : !fir.dscope
269 %1 = fir.shape %c100 : (index) -> !fir.shape<1>
270 %2 = fir.declare %arg0(%1) dummy_scope %0 {uniq_name = "_QFtest_explicit_shape_cst_chainEx"} : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, !fir.dscope) -> !fir.ref<!fir.array<100xf32>>
271 %3 = fir.shape %c50 : (index) -> !fir.shape<1>
272 %4 = fir.array_coor %2(%1) %c1 : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>
273 %5 = fir.convert %4 : (!fir.ref<f32>) -> !fir.ref<!fir.array<50xf32>>
274 %6 = fir.embox %5(%3) : (!fir.ref<!fir.array<50xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<50xf32>>
275 %7 = fir.convert %6 : (!fir.box<!fir.array<50xf32>>) -> !fir.box<!fir.array<?xf32>>
276 %8 = fir.dummy_scope : !fir.dscope
277 %9 = fir.pack_array %7 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
278 %10 = fir.declare %9 dummy_scope %8 {uniq_name = "_QFtest_explicit_shape_cst_chainFrepackEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
279 %11 = fir.rebox %10 : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
280 %12 = fir.dummy_scope : !fir.dscope
281 %13 = fir.pack_array %11 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
282 %14 = fir.declare %13 dummy_scope %12 {uniq_name = "_QMinnerFinner_repack1Ex"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
283 fir.unpack_array %13 to %11 heap : !fir.box<!fir.array<?xf32>>
284 fir.unpack_array %9 to %7 heap : !fir.box<!fir.array<?xf32>>
285 return
286 }
287
288 // subroutine test_explicit_shape_var_chain(x, n, l, u)
289 // integer :: n, l, u
290 // real :: x(n)
291 // call repack(x(l:u))
292 // contains
293 // subroutine repack(x)
294 // use inner
295 // real :: x(:)
296 // call inner_repack1(x)
297 // end subroutine repack
298 // end subroutine test_explicit_shape_var_chain
299 //
300 // CHECK-LABEL: func.func @_QPtest_explicit_shape_var_chain(
301 // CHECK-NOT: fir.{{.*}}pack_array
302 func.func @_QPtest_explicit_shape_var_chain(%arg0: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "x"}, %arg1: !fir.ref<i32> {fir.bindc_name = "n"}, %arg2: !fir.ref<i32> {fir.bindc_name = "l"}, %arg3: !fir.ref<i32> {fir.bindc_name = "u"}) {
303 %c1 = arith.constant 1 : index
304 %c0 = arith.constant 0 : index
305 %0 = fir.dummy_scope : !fir.dscope
306 %1 = fir.declare %arg2 dummy_scope %0 {uniq_name = "_QFtest_explicit_shape_var_chainEl"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
307 %2 = fir.declare %arg1 dummy_scope %0 {uniq_name = "_QFtest_explicit_shape_var_chainEn"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
308 %3 = fir.declare %arg3 dummy_scope %0 {uniq_name = "_QFtest_explicit_shape_var_chainEu"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
309 %4 = fir.load %2 : !fir.ref<i32>
310 %5 = fir.convert %4 : (i32) -> index
311 %6 = arith.cmpi sgt, %5, %c0 : index
312 %7 = arith.select %6, %5, %c0 : index
313 %8 = fir.shape %7 : (index) -> !fir.shape<1>
314 %9 = fir.declare %arg0(%8) dummy_scope %0 {uniq_name = "_QFtest_explicit_shape_var_chainEx"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, !fir.dscope) -> !fir.ref<!fir.array<?xf32>>
315 %10 = fir.load %1 : !fir.ref<i32>
316 %11 = fir.load %3 : !fir.ref<i32>
317 %12 = fir.convert %10 : (i32) -> index
318 %13 = fir.convert %11 : (i32) -> index
319 %14 = fir.slice %12, %13, %c1 : (index, index, index) -> !fir.slice<1>
320 %15 = fir.embox %9(%8) [%14] : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
321 %16 = fir.dummy_scope : !fir.dscope
322 %17 = fir.pack_array %15 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
323 %18 = fir.declare %17 dummy_scope %16 {uniq_name = "_QFtest_explicit_shape_var_chainFrepackEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
324 %19 = fir.rebox %18 : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
325 %20 = fir.dummy_scope : !fir.dscope
326 %21 = fir.pack_array %19 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
327 %22 = fir.declare %21 dummy_scope %20 {uniq_name = "_QMinnerFinner_repack1Ex"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
328 fir.unpack_array %21 to %19 heap : !fir.box<!fir.array<?xf32>>
329 fir.unpack_array %17 to %15 heap : !fir.box<!fir.array<?xf32>>
330 return
331 }
332
333 // subroutine test_assumed_size_cst_chain(x)
334 // real :: x(*)
335 // call repack(x(1:50))
336 // contains
337 // subroutine repack(x)
338 // use inner
339 // real :: x(:)
340 // call inner_repack1(x)
341 // end subroutine repack
342 // end subroutine test_assumed_size_cst_chain
343 //
344 // CHECK-LABEL: func.func @_QPtest_assumed_size_cst_chain(
345 // CHECK-NOT: fir.{{.*}}pack_array
346 func.func @_QPtest_assumed_size_cst_chain(%arg0: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "x"}) {
347 %c50 = arith.constant 50 : index
348 %c1 = arith.constant 1 : index
349 %c-1 = arith.constant -1 : index
350 %0 = fir.dummy_scope : !fir.dscope
351 %1 = fir.shape %c-1 : (index) -> !fir.shape<1>
352 %2 = fir.declare %arg0(%1) dummy_scope %0 {uniq_name = "_QFtest_assumed_size_cst_chainEx"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, !fir.dscope) -> !fir.ref<!fir.array<?xf32>>
353 %3 = fir.shape %c50 : (index) -> !fir.shape<1>
354 %4 = fir.array_coor %2(%1) %c1 : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>
355 %5 = fir.convert %4 : (!fir.ref<f32>) -> !fir.ref<!fir.array<50xf32>>
356 %6 = fir.embox %5(%3) : (!fir.ref<!fir.array<50xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<50xf32>>
357 %7 = fir.convert %6 : (!fir.box<!fir.array<50xf32>>) -> !fir.box<!fir.array<?xf32>>
358 %8 = fir.dummy_scope : !fir.dscope
359 %9 = fir.pack_array %7 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
360 %10 = fir.declare %9 dummy_scope %8 {uniq_name = "_QFtest_assumed_size_cst_chainFrepackEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
361 %11 = fir.rebox %10 : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
362 %12 = fir.dummy_scope : !fir.dscope
363 %13 = fir.pack_array %11 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
364 %14 = fir.declare %13 dummy_scope %12 {uniq_name = "_QMinnerFinner_repack1Ex"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
365 fir.unpack_array %13 to %11 heap : !fir.box<!fir.array<?xf32>>
366 fir.unpack_array %9 to %7 heap : !fir.box<!fir.array<?xf32>>
367 return
368 }
369
370 // subroutine test_assumed_size_var_chain(x, l, u)
371 // integer :: l, u
372 // real :: x(*)
373 // call repack(x(l:u))
374 // contains
375 // subroutine repack(x)
376 // use inner
377 // real :: x(:)
378 // call inner_repack1(x)
379 // end subroutine repack
380 // end subroutine test_assumed_size_var_chain
381 //
382 // CHECK-LABEL: func.func @_QPtest_assumed_size_var_chain(
383 // CHECK-NOT: fir.{{.*}}pack_array
384 func.func @_QPtest_assumed_size_var_chain(%arg0: !fir.ref<!fir.array<?xf32>> {fir.bindc_name = "x"}, %arg1: !fir.ref<i32> {fir.bindc_name = "l"}, %arg2: !fir.ref<i32> {fir.bindc_name = "u"}) {
385 %c1 = arith.constant 1 : index
386 %c-1 = arith.constant -1 : index
387 %0 = fir.dummy_scope : !fir.dscope
388 %1 = fir.declare %arg1 dummy_scope %0 {uniq_name = "_QFtest_assumed_size_var_chainEl"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
389 %2 = fir.declare %arg2 dummy_scope %0 {uniq_name = "_QFtest_assumed_size_var_chainEu"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
390 %3 = fir.shape %c-1 : (index) -> !fir.shape<1>
391 %4 = fir.declare %arg0(%3) dummy_scope %0 {uniq_name = "_QFtest_assumed_size_var_chainEx"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, !fir.dscope) -> !fir.ref<!fir.array<?xf32>>
392 %5 = fir.load %1 : !fir.ref<i32>
393 %6 = fir.load %2 : !fir.ref<i32>
394 %7 = fir.convert %5 : (i32) -> index
395 %8 = fir.convert %6 : (i32) -> index
396 %9 = fir.slice %7, %8, %c1 : (index, index, index) -> !fir.slice<1>
397 %10 = fir.embox %4(%3) [%9] : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
398 %11 = fir.dummy_scope : !fir.dscope
399 %12 = fir.pack_array %10 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
400 %13 = fir.declare %12 dummy_scope %11 {uniq_name = "_QFtest_assumed_size_var_chainFrepackEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
401 %14 = fir.rebox %13 : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
402 %15 = fir.dummy_scope : !fir.dscope
403 %16 = fir.pack_array %14 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
404 %17 = fir.declare %16 dummy_scope %15 {uniq_name = "_QMinnerFinner_repack1Ex"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
405 fir.unpack_array %16 to %14 heap : !fir.box<!fir.array<?xf32>>
406 fir.unpack_array %12 to %10 heap : !fir.box<!fir.array<?xf32>>
407 return
408 }
409
410 // subroutine test_allocatable_cst_chain(x)
411 // real, allocatable :: x(:)
412 // call repack(x(10:50))
413 // contains
414 // subroutine repack(x)
415 // use inner
416 // real :: x(:)
417 // call inner_repack1(x)
418 // end subroutine repack
419 // end subroutine test_allocatable_cst_chain
420 //
421 // CHECK-LABEL: func.func @_QPtest_allocatable_cst_chain(
422 // CHECK-NOT: fir.{{.*}}pack_array
423 func.func @_QPtest_allocatable_cst_chain(%arg0: !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> {fir.bindc_name = "x"}) {
424 %c0 = arith.constant 0 : index
425 %c41 = arith.constant 41 : index
426 %c10 = arith.constant 10 : index
427 %0 = fir.dummy_scope : !fir.dscope
428 %1 = fir.declare %arg0 dummy_scope %0 {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest_allocatable_cst_chainEx"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>, !fir.dscope) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
429 %2 = fir.load %1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
430 %3 = fir.shape %c41 : (index) -> !fir.shape<1>
431 %4 = fir.box_addr %2 : (!fir.box<!fir.heap<!fir.array<?xf32>>>) -> !fir.heap<!fir.array<?xf32>>
432 %5:3 = fir.box_dims %2, %c0 : (!fir.box<!fir.heap<!fir.array<?xf32>>>, index) -> (index, index, index)
433 %6 = fir.shape_shift %5#0, %5#1 : (index, index) -> !fir.shapeshift<1>
434 %7 = fir.array_coor %4(%6) %c10 : (!fir.heap<!fir.array<?xf32>>, !fir.shapeshift<1>, index) -> !fir.ref<f32>
435 %8 = fir.convert %7 : (!fir.ref<f32>) -> !fir.ref<!fir.array<41xf32>>
436 %9 = fir.embox %8(%3) : (!fir.ref<!fir.array<41xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<41xf32>>
437 %10 = fir.convert %9 : (!fir.box<!fir.array<41xf32>>) -> !fir.box<!fir.array<?xf32>>
438 %11 = fir.dummy_scope : !fir.dscope
439 %12 = fir.pack_array %10 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
440 %13 = fir.declare %12 dummy_scope %11 {uniq_name = "_QFtest_allocatable_cst_chainFrepackEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
441 %14 = fir.rebox %13 : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
442 %15 = fir.dummy_scope : !fir.dscope
443 %16 = fir.pack_array %14 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
444 %17 = fir.declare %16 dummy_scope %15 {uniq_name = "_QMinnerFinner_repack1Ex"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
445 fir.unpack_array %16 to %14 heap : !fir.box<!fir.array<?xf32>>
446 fir.unpack_array %12 to %10 heap : !fir.box<!fir.array<?xf32>>
447 return
448 }
449
450 // subroutine test_allocatable_var_chain(x, l, u)
451 // integer :: l, u
452 // real, allocatable :: x(:)
453 // call repack(x(l:u))
454 // contains
455 // subroutine repack(x)
456 // use inner
457 // real :: x(:)
458 // call inner_repack1(x)
459 // end subroutine repack
460 // end subroutine test_allocatable_var_chain
461 //
462 // CHECK-LABEL: func.func @_QPtest_allocatable_var_chain(
463 // CHECK-NOT: fir.{{.*}}pack_array
464 func.func @_QPtest_allocatable_var_chain(%arg0: !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>> {fir.bindc_name = "x"}, %arg1: !fir.ref<i32> {fir.bindc_name = "l"}, %arg2: !fir.ref<i32> {fir.bindc_name = "u"}) {
465 %c0 = arith.constant 0 : index
466 %c1 = arith.constant 1 : index
467 %0 = fir.dummy_scope : !fir.dscope
468 %1 = fir.declare %arg1 dummy_scope %0 {uniq_name = "_QFtest_allocatable_var_chainEl"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
469 %2 = fir.declare %arg2 dummy_scope %0 {uniq_name = "_QFtest_allocatable_var_chainEu"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
470 %3 = fir.declare %arg0 dummy_scope %0 {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest_allocatable_var_chainEx"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>, !fir.dscope) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
471 %4 = fir.load %3 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
472 %5 = fir.load %1 : !fir.ref<i32>
473 %6 = fir.load %2 : !fir.ref<i32>
474 %7 = fir.convert %5 : (i32) -> index
475 %8 = fir.convert %6 : (i32) -> index
476 %9 = fir.box_addr %4 : (!fir.box<!fir.heap<!fir.array<?xf32>>>) -> !fir.heap<!fir.array<?xf32>>
477 %10:3 = fir.box_dims %4, %c0 : (!fir.box<!fir.heap<!fir.array<?xf32>>>, index) -> (index, index, index)
478 %11 = fir.shape_shift %10#0, %10#1 : (index, index) -> !fir.shapeshift<1>
479 %12 = fir.slice %7, %8, %c1 : (index, index, index) -> !fir.slice<1>
480 %13 = fir.embox %9(%11) [%12] : (!fir.heap<!fir.array<?xf32>>, !fir.shapeshift<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
481 %14 = fir.dummy_scope : !fir.dscope
482 %15 = fir.pack_array %13 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
483 %16 = fir.declare %15 dummy_scope %14 {uniq_name = "_QFtest_allocatable_var_chainFrepackEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
484 %17 = fir.rebox %16 : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
485 %18 = fir.dummy_scope : !fir.dscope
486 %19 = fir.pack_array %17 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
487 %20 = fir.declare %19 dummy_scope %18 {uniq_name = "_QMinnerFinner_repack1Ex"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
488 fir.unpack_array %19 to %17 heap : !fir.box<!fir.array<?xf32>>
489 fir.unpack_array %15 to %13 heap : !fir.box<!fir.array<?xf32>>
490 return
491 }
492
493 // subroutine test_allocatable_full_chain(x)
494 // real, allocatable :: x(:,:)
495 // call repack(x(:,:))
496 // contains
497 // subroutine repack(x)
498 // use inner
499 // real :: x(:,:)
500 // call inner_repack2(x)
501 // end subroutine repack
502 // end subroutine test_allocatable_full_chain
503 //
504 // CHECK-LABEL: func.func @_QPtest_allocatable_full_chain(
505 // CHECK-NOT: fir.{{.*}}pack_array
506 func.func @_QPtest_allocatable_full_chain(%arg0: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>> {fir.bindc_name = "x"}) {
507 %c1 = arith.constant 1 : index
508 %c0 = arith.constant 0 : index
509 %0 = fir.dummy_scope : !fir.dscope
510 %1 = fir.declare %arg0 dummy_scope %0 {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest_allocatable_full_chainEx"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>, !fir.dscope) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>
511 %2 = fir.load %1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>
512 %3:3 = fir.box_dims %2, %c0 : (!fir.box<!fir.heap<!fir.array<?x?xf32>>>, index) -> (index, index, index)
513 %4:3 = fir.box_dims %2, %c1 : (!fir.box<!fir.heap<!fir.array<?x?xf32>>>, index) -> (index, index, index)
514 %5 = arith.addi %3#0, %3#1 : index
515 %6 = arith.subi %5, %c1 : index
516 %7 = arith.addi %4#0, %4#1 : index
517 %8 = arith.subi %7, %c1 : index
518 %9 = fir.box_addr %2 : (!fir.box<!fir.heap<!fir.array<?x?xf32>>>) -> !fir.heap<!fir.array<?x?xf32>>
519 %10 = fir.shape_shift %3#0, %3#1, %4#0, %4#1 : (index, index, index, index) -> !fir.shapeshift<2>
520 %11 = fir.slice %3#0, %6, %c1, %4#0, %8, %c1 : (index, index, index, index, index, index) -> !fir.slice<2>
521 %12 = fir.embox %9(%10) [%11] : (!fir.heap<!fir.array<?x?xf32>>, !fir.shapeshift<2>, !fir.slice<2>) -> !fir.box<!fir.array<?x?xf32>>
522 %13 = fir.dummy_scope : !fir.dscope
523 %14 = fir.pack_array %12 heap innermost : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<!fir.array<?x?xf32>>
524 %15 = fir.declare %14 dummy_scope %13 {uniq_name = "_QFtest_allocatable_full_chainFrepackEx"} : (!fir.box<!fir.array<?x?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?x?xf32>>
525 %16 = fir.rebox %15 : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<!fir.array<?x?xf32>>
526 %17 = fir.dummy_scope : !fir.dscope
527 %18 = fir.pack_array %16 heap innermost : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<!fir.array<?x?xf32>>
528 %19 = fir.declare %18 dummy_scope %17 {uniq_name = "_QMinnerFinner_repack2Ex"} : (!fir.box<!fir.array<?x?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?x?xf32>>
529 fir.unpack_array %18 to %16 heap : !fir.box<!fir.array<?x?xf32>>
530 fir.unpack_array %14 to %12 heap : !fir.box<!fir.array<?x?xf32>>
531 return
532 }
533
534 // TODO: if both fir.pack_array have the same property,
535 // then the second one is redundant, because the first
536 // repack makes 'x' contiguous.
537 // subroutine neg_test_assumed_shape(x)
538 // real :: x(:)
539 // call repack(x(1:50))
540 // contains
541 // subroutine repack(x)
542 // real :: x(:)
543 // end subroutine repack
544 // end subroutine neg_test_assumed_shape
545 //
546 // CHECK-LABEL: func.func @_QPneg_test_assumed_shape(
547 // CHECK: fir.pack_array
548 // CHECK: fir.pack_array
549 // CHECK: fir.unpack_array
550 // CHECK: fir.unpack_array
551 func.func @_QPneg_test_assumed_shape(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}) {
552 %c50 = arith.constant 50 : index
553 %c1 = arith.constant 1 : index
554 %0 = fir.dummy_scope : !fir.dscope
555 %1 = fir.pack_array %arg0 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
556 %2 = fir.declare %1 dummy_scope %0 {uniq_name = "_QFneg_test_assumed_shapeEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
557 %3 = fir.rebox %2 : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
558 %4 = fir.slice %c1, %c50, %c1 : (index, index, index) -> !fir.slice<1>
559 %5 = fir.rebox %3 [%4] : (!fir.box<!fir.array<?xf32>>, !fir.slice<1>) -> !fir.box<!fir.array<50xf32>>
560 %6 = fir.convert %5 : (!fir.box<!fir.array<50xf32>>) -> !fir.box<!fir.array<?xf32>>
561 %7 = fir.dummy_scope : !fir.dscope
562 %8 = fir.pack_array %6 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
563 %9 = fir.declare %8 dummy_scope %7 {uniq_name = "_QFneg_test_assumed_shapeFrepackEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
564 fir.unpack_array %8 to %6 heap : !fir.box<!fir.array<?xf32>>
565 fir.unpack_array %1 to %arg0 heap : !fir.box<!fir.array<?xf32>>
566 return
567 }
568
569 // subroutine neg_test_non_contig_slice_cst(x)
570 // real :: x(100)
571 // call repack(x(1:50:2))
572 // contains
573 // subroutine repack(x)
574 // real :: x(:)
575 // end subroutine repack
576 // end subroutine neg_test_non_contig_slice_cst
577 //
578 // CHECK-LABEL: func.func @_QPneg_test_non_contig_slice_cst(
579 // CHECK: fir.pack_array
580 // CHECK: fir.unpack_array
581 func.func @_QPneg_test_non_contig_slice_cst(%arg0: !fir.ref<!fir.array<100xf32>> {fir.bindc_name = "x"}) {
582 %c2 = arith.constant 2 : index
583 %c50 = arith.constant 50 : index
584 %c1 = arith.constant 1 : index
585 %c100 = arith.constant 100 : index
586 %0 = fir.dummy_scope : !fir.dscope
587 %1 = fir.shape %c100 : (index) -> !fir.shape<1>
588 %2 = fir.declare %arg0(%1) dummy_scope %0 {uniq_name = "_QFneg_test_non_contig_slice_cstEx"} : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, !fir.dscope) -> !fir.ref<!fir.array<100xf32>>
589 %3 = fir.slice %c1, %c50, %c2 : (index, index, index) -> !fir.slice<1>
590 %4 = fir.embox %2(%1) [%3] : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box<!fir.array<25xf32>>
591 %5 = fir.convert %4 : (!fir.box<!fir.array<25xf32>>) -> !fir.box<!fir.array<?xf32>>
592 %6 = fir.dummy_scope : !fir.dscope
593 %7 = fir.pack_array %5 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
594 %8 = fir.declare %7 dummy_scope %6 {uniq_name = "_QFneg_test_non_contig_slice_cstFrepackEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
595 fir.unpack_array %7 to %5 heap : !fir.box<!fir.array<?xf32>>
596 return
597 }
598
599 // subroutine neg_test_non_contig_slice_var(x, s)
600 // integer :: s
601 // real :: x(100)
602 // call repack(x(1:50:s))
603 // contains
604 // subroutine repack(x)
605 // real :: x(:)
606 // end subroutine repack
607 // end subroutine neg_test_non_contig_slice_var
608 //
609 // CHECK-LABEL: func.func @_QPneg_test_non_contig_slice_var(
610 // CHECK: fir.pack_array
611 // CHECK: fir.unpack_array
612 func.func @_QPneg_test_non_contig_slice_var(%arg0: !fir.ref<!fir.array<100xf32>> {fir.bindc_name = "x"}, %arg1: !fir.ref<i32> {fir.bindc_name = "s"}) {
613 %c50 = arith.constant 50 : index
614 %c1 = arith.constant 1 : index
615 %c100 = arith.constant 100 : index
616 %0 = fir.dummy_scope : !fir.dscope
617 %1 = fir.declare %arg1 dummy_scope %0 {uniq_name = "_QFneg_test_non_contig_slice_varEs"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
618 %2 = fir.shape %c100 : (index) -> !fir.shape<1>
619 %3 = fir.declare %arg0(%2) dummy_scope %0 {uniq_name = "_QFneg_test_non_contig_slice_varEx"} : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, !fir.dscope) -> !fir.ref<!fir.array<100xf32>>
620 %4 = fir.load %1 : !fir.ref<i32>
621 %5 = fir.convert %4 : (i32) -> index
622 %6 = fir.slice %c1, %c50, %5 : (index, index, index) -> !fir.slice<1>
623 %7 = fir.embox %3(%2) [%6] : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
624 %8 = fir.dummy_scope : !fir.dscope
625 %9 = fir.pack_array %7 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
626 %10 = fir.declare %9 dummy_scope %8 {uniq_name = "_QFneg_test_non_contig_slice_varFrepackEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
627 fir.unpack_array %9 to %7 heap : !fir.box<!fir.array<?xf32>>
628 return
629 }
630
631 // subroutine neg_test_pointer(x)
632 // real, pointer :: x(:)
633 // call repack(x(1:50))
634 // contains
635 // subroutine repack(x)
636 // real :: x(:)
637 // end subroutine repack
638 // end subroutine neg_test_pointer
639 //
640 // CHECK-LABEL: func.func @_QPneg_test_pointer(
641 // CHECK: fir.pack_array
642 // CHECK: fir.unpack_array
643 func.func @_QPneg_test_pointer(%arg0: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> {fir.bindc_name = "x"}) {
644 %c0 = arith.constant 0 : index
645 %c50 = arith.constant 50 : index
646 %c1 = arith.constant 1 : index
647 %0 = fir.dummy_scope : !fir.dscope
648 %1 = fir.declare %arg0 dummy_scope %0 {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFneg_test_pointerEx"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>, !fir.dscope) -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
649 %2 = fir.load %1 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
650 %3:3 = fir.box_dims %2, %c0 : (!fir.box<!fir.ptr<!fir.array<?xf32>>>, index) -> (index, index, index)
651 %4 = fir.shift %3#0 : (index) -> !fir.shift<1>
652 %5 = fir.slice %c1, %c50, %c1 : (index, index, index) -> !fir.slice<1>
653 %6 = fir.rebox %2(%4) [%5] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>, !fir.shift<1>, !fir.slice<1>) -> !fir.box<!fir.array<50xf32>>
654 %7 = fir.convert %6 : (!fir.box<!fir.array<50xf32>>) -> !fir.box<!fir.array<?xf32>>
655 %8 = fir.dummy_scope : !fir.dscope
656 %9 = fir.pack_array %7 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
657 %10 = fir.declare %9 dummy_scope %8 {uniq_name = "_QFneg_test_pointerFrepackEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> !fir.box<!fir.array<?xf32>>
658 fir.unpack_array %9 to %7 heap : !fir.box<!fir.array<?xf32>>
659 return
660 }