|
| 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 |
| 9 | + |
| 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 |
| 41 | +} |
| 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: } |
| 52 | + |
| 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 |
| 74 | +} |
| 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: } |
| 85 | + |
| 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 |
| 120 | +} |
| 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: } |
0 commit comments