1// RUN: fir-opt --array-value-copy --cfg-conversion %s | FileCheck %s
2
3// CHECK-LABEL: func @_QPslice1(
4// CHECK-NOT: fir.allocmem
5// CHECK: ^bb{{[0-9]+}}(%{{[0-9]+}}: index,
6// CHECK-NOT: ^bb{{[0-9]+}}(%{{[0-9]+}}: index,
7// CHECK: return
8func.func @_QPslice1(%arg0: !fir.box<!fir.array<?xf32>>, %arg1: !fir.ref<i32>, %arg2: !fir.ref<i32>) {
9  %c1_i64 = arith.constant 1 : i64
10  %0 = fir.convert %c1_i64 : (i64) -> index
11  %1 = fir.load %arg1 : !fir.ref<i32>
12  %2 = fir.convert %1 : (i32) -> i64
13  %3 = fir.convert %2 : (i64) -> index
14  %c0 = arith.constant 0 : index
15  %4 = arith.subi %3, %0 : index
16  %5 = arith.addi %4, %0 : index
17  %6 = arith.divsi %5, %0 : index
18  %7 = arith.cmpi sgt, %6, %c0 : index
19  %8 = arith.select %7, %6, %c0 : index
20  %9 = fir.slice %0, %3, %0 : (index, index, index) -> !fir.slice<1>
21  %10 = fir.array_load %arg0 [%9] : (!fir.box<!fir.array<?xf32>>, !fir.slice<1>) -> !fir.array<?xf32>
22  %c1_i32 = arith.constant 1 : i32
23  %11 = arith.addi %1, %c1_i32 : i32
24  %12 = fir.convert %11 : (i32) -> i64
25  %13 = fir.convert %12 : (i64) -> index
26  %14 = fir.load %arg2 : !fir.ref<i32>
27  %15 = fir.convert %14 : (i32) -> i64
28  %16 = fir.convert %15 : (i64) -> index
29  %17 = fir.slice %13, %16, %0 : (index, index, index) -> !fir.slice<1>
30  %18 = fir.array_load %arg0 [%17] : (!fir.box<!fir.array<?xf32>>, !fir.slice<1>) -> !fir.array<?xf32>
31  %c1 = arith.constant 1 : index
32  %19 = arith.subi %8, %c1 : index
33  %20 = fir.do_loop %arg3 = %c0 to %19 step %c1 unordered iter_args(%arg4 = %10) -> (!fir.array<?xf32>) {
34    %21 = fir.array_fetch %18, %arg3 : (!fir.array<?xf32>, index) -> f32
35    %22 = fir.array_update %arg4, %21, %arg3 : (!fir.array<?xf32>, f32, index) -> !fir.array<?xf32>
36    fir.result %22 : !fir.array<?xf32>
37  }
38  fir.array_merge_store %10, %20 to %arg0[%9] : !fir.array<?xf32>, !fir.array<?xf32>, !fir.box<!fir.array<?xf32>>, !fir.slice<1>
39  return
40}
41
42// CHECK-LABEL: func @_QPslice2(
43// CHECK: fir.allocmem
44// CHECK: ^bb{{[0-9]+}}(%{{[0-9]+}}: index,
45// CHECK: ^bb{{[0-9]+}}(%{{[0-9]+}}: index,
46// CHECK: fir.freemem
47// CHECK: return
48func.func @_QPslice2(%arg0: !fir.box<!fir.array<?xf32>>, %arg1: !fir.ref<i32>, %arg2: !fir.ref<i32>) {
49  %c1_i64 = arith.constant 1 : i64
50  %0 = fir.convert %c1_i64 : (i64) -> index
51  %c1_i64_0 = arith.constant 1 : i64
52  %1 = fir.convert %c1_i64_0 : (i64) -> index
53  %2 = fir.load %arg1 : !fir.ref<i32>
54  %3 = fir.convert %2 : (i32) -> i64
55  %4 = fir.convert %3 : (i64) -> index
56  %c0 = arith.constant 0 : index
57  %5 = arith.subi %4, %0 : index
58  %6 = arith.addi %5, %1 : index
59  %7 = arith.divsi %6, %1 : index
60  %8 = arith.cmpi sgt, %7, %c0 : index
61  %9 = arith.select %8, %7, %c0 : index
62  %10 = fir.slice %0, %4, %1 : (index, index, index) -> !fir.slice<1>
63  %11 = fir.array_load %arg0 [%10] : (!fir.box<!fir.array<?xf32>>, !fir.slice<1>) -> !fir.array<?xf32>
64  %12 = fir.load %arg1 : !fir.ref<i32>
65  %c4_i32 = arith.constant 4 : i32
66  %13 = arith.subi %12, %c4_i32 : i32
67  %14 = fir.convert %13 : (i32) -> i64
68  %15 = fir.convert %14 : (i64) -> index
69  %c1_i64_1 = arith.constant 1 : i64
70  %16 = fir.convert %c1_i64_1 : (i64) -> index
71  %17 = fir.load %arg2 : !fir.ref<i32>
72  %18 = fir.convert %17 : (i32) -> i64
73  %19 = fir.convert %18 : (i64) -> index
74  %20 = fir.slice %15, %19, %16 : (index, index, index) -> !fir.slice<1>
75  %21 = fir.array_load %arg0 [%20] : (!fir.box<!fir.array<?xf32>>, !fir.slice<1>) -> !fir.array<?xf32>
76  %c1 = arith.constant 1 : index
77  %c0_2 = arith.constant 0 : index
78  %22 = arith.subi %9, %c1 : index
79  %23 = fir.do_loop %arg3 = %c0_2 to %22 step %c1 unordered iter_args(%arg4 = %11) -> (!fir.array<?xf32>) {
80    %24 = fir.array_fetch %21, %arg3 : (!fir.array<?xf32>, index) -> f32
81    %25 = fir.array_update %arg4, %24, %arg3 : (!fir.array<?xf32>, f32, index) -> !fir.array<?xf32>
82    fir.result %25 : !fir.array<?xf32>
83  }
84  fir.array_merge_store %11, %23 to %arg0[%10] : !fir.array<?xf32>, !fir.array<?xf32>, !fir.box<!fir.array<?xf32>>, !fir.slice<1>
85  return
86}
87