brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · b558482 Raw
55 lines · plain
1// RUN: fir-opt --opt-bufferization %s | FileCheck %s2 3// Check that the elemental+assign are rewritten into a loop4// with "optimal" loop bounds, e.g. that we use constants5// when possible.6 7// CHECK-LABEL:   func.func @_QPtest1(8// CHECK:           %[[VAL_0:.*]] = arith.constant 1 : index9// CHECK:           %[[VAL_1:.*]] = arith.constant 3 : index10// CHECK:           fir.do_loop %[[VAL_6:.*]] = %[[VAL_0]] to %[[VAL_1]] step %[[VAL_0]] unordered {11// CHECK-NOT: hlfir.assign{{.*}}array12func.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 : index14  %c3 = arith.constant 3 : index15  %0 = fir.dummy_scope : !fir.dscope16  %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> : f3226    hlfir.yield_element %9 : f3227  }28  hlfir.assign %6 to %3#0 : !hlfir.expr<?xf32>, !fir.ref<!fir.array<3xf32>>29  hlfir.destroy %6 : !hlfir.expr<?xf32>30  return31}32 33// CHECK-LABEL:   func.func @_QPtest2(34// CHECK:           %[[VAL_0:.*]] = arith.constant 1 : index35// CHECK:           %[[VAL_1:.*]] = arith.constant 3 : index36// CHECK:           fir.do_loop %[[VAL_6:.*]] = %[[VAL_0]] to %[[VAL_1]] step %[[VAL_0]] unordered {37// CHECK-NOT: hlfir.assign{{.*}}array38func.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 : index40  %0 = fir.dummy_scope : !fir.dscope41  %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> : f3249    hlfir.yield_element %7 : f3250  }51  hlfir.assign %4 to %1#0 : !hlfir.expr<3xf32>, !fir.box<!fir.array<?xf32>>52  hlfir.destroy %4 : !hlfir.expr<3xf32>53  return54}55