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