|
| 1 | +// RUN: fir-opt --opt-bufferization %s | FileCheck %s |
| 2 | + |
| 3 | +// Check that the elemental+assign are rewritten into a loop |
| 4 | +// with "optimal" loop bounds, e.g. that we use constants |
| 5 | +// when possible. |
| 6 | + |
| 7 | +// CHECK-LABEL: func.func @_QPtest1( |
| 8 | +// CHECK: %[[VAL_0:.*]] = arith.constant 1 : index |
| 9 | +// CHECK: %[[VAL_1:.*]] = arith.constant 3 : index |
| 10 | +// CHECK: fir.do_loop %[[VAL_6:.*]] = %[[VAL_0]] to %[[VAL_1]] step %[[VAL_0]] unordered { |
| 11 | +// CHECK-NOT: hlfir.assign{{.*}}array |
| 12 | +func.func @_QPtest1(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}, %arg1: !fir.ref<!fir.array<3xf32>> {fir.bindc_name = "y"}) { |
| 13 | + %c0 = arith.constant 0 : index |
| 14 | + %c3 = arith.constant 3 : index |
| 15 | + %0 = fir.dummy_scope : !fir.dscope |
| 16 | + %1:2 = hlfir.declare %arg0 dummy_scope %0 {uniq_name = "_QFtest1Ex"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>) |
| 17 | + %2 = fir.shape %c3 : (index) -> !fir.shape<1> |
| 18 | + %3:2 = hlfir.declare %arg1(%2) dummy_scope %0 {uniq_name = "_QFtest1Ey"} : (!fir.ref<!fir.array<3xf32>>, !fir.shape<1>, !fir.dscope) -> (!fir.ref<!fir.array<3xf32>>, !fir.ref<!fir.array<3xf32>>) |
| 19 | + %4:3 = fir.box_dims %1#0, %c0 : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index) |
| 20 | + %5 = fir.shape %4#1 : (index) -> !fir.shape<1> |
| 21 | + %6 = hlfir.elemental %5 unordered : (!fir.shape<1>) -> !hlfir.expr<?xf32> { |
| 22 | + ^bb0(%arg2: index): |
| 23 | + %7 = hlfir.designate %1#0 (%arg2) : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32> |
| 24 | + %8 = fir.load %7 : !fir.ref<f32> |
| 25 | + %9 = arith.addf %8, %8 fastmath<contract> : f32 |
| 26 | + hlfir.yield_element %9 : f32 |
| 27 | + } |
| 28 | + hlfir.assign %6 to %3#0 : !hlfir.expr<?xf32>, !fir.ref<!fir.array<3xf32>> |
| 29 | + hlfir.destroy %6 : !hlfir.expr<?xf32> |
| 30 | + return |
| 31 | +} |
| 32 | + |
| 33 | +// CHECK-LABEL: func.func @_QPtest2( |
| 34 | +// CHECK: %[[VAL_0:.*]] = arith.constant 1 : index |
| 35 | +// CHECK: %[[VAL_1:.*]] = arith.constant 3 : index |
| 36 | +// CHECK: fir.do_loop %[[VAL_6:.*]] = %[[VAL_0]] to %[[VAL_1]] step %[[VAL_0]] unordered { |
| 37 | +// CHECK-NOT: hlfir.assign{{.*}}array |
| 38 | +func.func @_QPtest2(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}, %arg1: !fir.ref<!fir.array<3xf32>> {fir.bindc_name = "y"}) { |
| 39 | + %c3 = arith.constant 3 : index |
| 40 | + %0 = fir.dummy_scope : !fir.dscope |
| 41 | + %1:2 = hlfir.declare %arg0 dummy_scope %0 {uniq_name = "_QFtest2Ex"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>) |
| 42 | + %2 = fir.shape %c3 : (index) -> !fir.shape<1> |
| 43 | + %3:2 = hlfir.declare %arg1(%2) dummy_scope %0 {uniq_name = "_QFtest2Ey"} : (!fir.ref<!fir.array<3xf32>>, !fir.shape<1>, !fir.dscope) -> (!fir.ref<!fir.array<3xf32>>, !fir.ref<!fir.array<3xf32>>) |
| 44 | + %4 = hlfir.elemental %2 unordered : (!fir.shape<1>) -> !hlfir.expr<3xf32> { |
| 45 | + ^bb0(%arg2: index): |
| 46 | + %5 = hlfir.designate %3#0 (%arg2) : (!fir.ref<!fir.array<3xf32>>, index) -> !fir.ref<f32> |
| 47 | + %6 = fir.load %5 : !fir.ref<f32> |
| 48 | + %7 = arith.addf %6, %6 fastmath<contract> : f32 |
| 49 | + hlfir.yield_element %7 : f32 |
| 50 | + } |
| 51 | + hlfir.assign %4 to %1#0 : !hlfir.expr<3xf32>, !fir.box<!fir.array<?xf32>> |
| 52 | + hlfir.destroy %4 : !hlfir.expr<3xf32> |
| 53 | + return |
| 54 | +} |
0 commit comments