70 lines · plain
1// RUN: fir-opt --opt-bufferization %s | FileCheck %s2 3// Verify that the hlfir.assign of hlfir.elemental is optimized4// into element-per-element assignment:5// subroutine test1(p)6// real, pointer :: p(:)7// p = p + 1.08// end subroutine test19 10func.func @_QPtest1(%arg0: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> {fir.bindc_name = "p"}) {11 %c1 = arith.constant 1 : index12 %c0 = arith.constant 0 : index13 %cst = arith.constant 1.000000e+00 : f3214 %0 = fir.dummy_scope : !fir.dscope15 %1:2 = hlfir.declare %arg0 dummy_scope %0 {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtest1Ep"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>)16 %2 = fir.load %1#0 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>17 %3:3 = fir.box_dims %2, %c0 : (!fir.box<!fir.ptr<!fir.array<?xf32>>>, index) -> (index, index, index)18 %4 = fir.shape %3#1 : (index) -> !fir.shape<1>19 %5 = hlfir.elemental %4 unordered : (!fir.shape<1>) -> !hlfir.expr<?xf32> {20 ^bb0(%arg1: index):21 %6 = arith.subi %3#0, %c1 : index22 %7 = arith.addi %arg1, %6 : index23 %8 = hlfir.designate %2 (%7) : (!fir.box<!fir.ptr<!fir.array<?xf32>>>, index) -> !fir.ref<f32>24 %9 = fir.load %8 : !fir.ref<f32>25 %10 = arith.addf %9, %cst fastmath<contract> : f3226 hlfir.yield_element %10 : f3227 }28 hlfir.assign %5 to %2 : !hlfir.expr<?xf32>, !fir.box<!fir.ptr<!fir.array<?xf32>>>29 hlfir.destroy %5 : !hlfir.expr<?xf32>30 return31}32// CHECK-LABEL: func.func @_QPtest1(33// CHECK-NOT: hlfir.assign34// CHECK: hlfir.assign %{{.*}} to %{{.*}} : f32, !fir.ref<f32>35// CHECK-NOT: hlfir.assign36 37// subroutine test2(p)38// real, pointer :: p(:,:)39// p = p + 1.040// end subroutine test241func.func @_QPtest2(%arg0: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>> {fir.bindc_name = "p"}) {42 %c1 = arith.constant 1 : index43 %c0 = arith.constant 0 : index44 %cst = arith.constant 1.000000e+00 : f3245 %0 = fir.dummy_scope : !fir.dscope46 %1:2 = hlfir.declare %arg0 dummy_scope %0 {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtest2Ep"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>)47 %2 = fir.load %1#0 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>48 %3:3 = fir.box_dims %2, %c0 : (!fir.box<!fir.ptr<!fir.array<?x?xf32>>>, index) -> (index, index, index)49 %4:3 = fir.box_dims %2, %c1 : (!fir.box<!fir.ptr<!fir.array<?x?xf32>>>, index) -> (index, index, index)50 %5 = fir.shape %3#1, %4#1 : (index, index) -> !fir.shape<2>51 %6 = hlfir.elemental %5 unordered : (!fir.shape<2>) -> !hlfir.expr<?x?xf32> {52 ^bb0(%arg1: index, %arg2: index):53 %7 = arith.subi %3#0, %c1 : index54 %8 = arith.addi %arg1, %7 : index55 %9 = arith.subi %4#0, %c1 : index56 %10 = arith.addi %arg2, %9 : index57 %11 = hlfir.designate %2 (%8, %10) : (!fir.box<!fir.ptr<!fir.array<?x?xf32>>>, index, index) -> !fir.ref<f32>58 %12 = fir.load %11 : !fir.ref<f32>59 %13 = arith.addf %12, %cst fastmath<contract> : f3260 hlfir.yield_element %13 : f3261 }62 hlfir.assign %6 to %2 : !hlfir.expr<?x?xf32>, !fir.box<!fir.ptr<!fir.array<?x?xf32>>>63 hlfir.destroy %6 : !hlfir.expr<?x?xf32>64 return65}66// CHECK-LABEL: func.func @_QPtest2(67// CHECK-NOT: hlfir.assign68// CHECK: hlfir.assign %{{.*}} to %{{.*}} : f32, !fir.ref<f32>69// CHECK-NOT: hlfir.assign70