// RUN: fir-opt -flang-licm --split-input-file %s | FileCheck %s // Test that a load of a scalar allocated by fir.allocmem // is hoisted out of the loop (the allocation proves // the variable is always present). // CHECK-LABEL: func.func @test_allocmem( // CHECK: %[[ALLOCMEM:.*]] = fir.allocmem f32 // CHECK: %[[DECLARE:.*]] = fir.declare %[[ALLOCMEM]] {uniq_name = "_QFtestEy"} // CHECK: %[[LOAD:.*]] = fir.load %[[DECLARE]] // CHECK: fir.do_loop // CHECK-NOT: fir.load func.func @test_allocmem(%arg0: !fir.ref> {fir.bindc_name = "x"}, %arg1: !fir.ref {fir.bindc_name = "n"}) { %c1 = arith.constant 1 : index %0 = fir.dummy_scope : !fir.dscope %1 = fir.allocmem f32 {uniq_name = "_QFtestEy.alloc"} %2 = fir.declare %1 {uniq_name = "_QFtestEy"} : (!fir.heap) -> !fir.heap %3 = fir.declare %arg1 dummy_scope %0 arg 2 {uniq_name = "_QFtestEn"} : (!fir.ref, !fir.dscope) -> !fir.ref %4 = fir.load %3 : !fir.ref %n = fir.convert %4 : (i32) -> index %5 = fir.shape %n : (index) -> !fir.shape<1> %6 = fir.declare %arg0(%5) dummy_scope %0 arg 1 {uniq_name = "_QFtestEx"} : (!fir.ref>, !fir.shape<1>, !fir.dscope) -> !fir.ref> fir.do_loop %arg2 = %c1 to %n step %c1 { %7 = fir.load %2 : !fir.heap %8 = fir.array_coor %6(%5) %arg2 : (!fir.ref>, !fir.shape<1>, index) -> !fir.ref fir.store %7 to %8 : !fir.ref } fir.freemem %2 : !fir.heap return } // ----- // Test that a load of a scalar allocated by cuf.alloc // is hoisted out of the loop (the allocation proves // the variable is always present). // CHECK-LABEL: func.func @test_cuf_alloc( // CHECK: %[[ALLOC:.*]] = cuf.alloc f32 // CHECK: %[[DECLARE:.*]] = fir.declare %[[ALLOC]] // CHECK: %[[LOAD:.*]] = fir.load %[[DECLARE]] // CHECK: fir.do_loop // CHECK-NOT: fir.load func.func @test_cuf_alloc(%arg0: !fir.ref> {cuf.data_attr = #cuf.cuda, fir.bindc_name = "x"}, %arg1: !fir.ref {fir.bindc_name = "n"}) { %c1 = arith.constant 1 : index %0 = fir.dummy_scope : !fir.dscope %1 = cuf.alloc f32 {data_attr = #cuf.cuda, uniq_name = "_QFtestEy"} -> !fir.ref %2 = fir.declare %1 {data_attr = #cuf.cuda, uniq_name = "_QFtestEy"} : (!fir.ref) -> !fir.ref %3 = fir.declare %arg1 dummy_scope %0 arg 2 {uniq_name = "_QFtestEn"} : (!fir.ref, !fir.dscope) -> !fir.ref %4 = fir.load %3 : !fir.ref %n = fir.convert %4 : (i32) -> index %5 = fir.shape %n : (index) -> !fir.shape<1> %6 = fir.declare %arg0(%5) dummy_scope %0 arg 1 {data_attr = #cuf.cuda, uniq_name = "_QFtestEx"} : (!fir.ref>, !fir.shape<1>, !fir.dscope) -> !fir.ref> fir.do_loop %arg2 = %c1 to %n step %c1 { %7 = fir.load %2 : !fir.ref %8 = fir.array_coor %6(%5) %arg2 : (!fir.ref>, !fir.shape<1>, index) -> !fir.ref fir.store %7 to %8 : !fir.ref } cuf.free %1 : !fir.ref {data_attr = #cuf.cuda} return }