75 lines · plain
1// Test rewrite of fir.declare. The result is replaced by the memref operand.2// RUN: fir-opt --cg-rewrite="preserve-declare=true" %s -o - | FileCheck %s --check-prefixes DECL3// RUN: fir-opt --cg-rewrite="preserve-declare=false" %s -o - | FileCheck %s --check-prefixes NODECL4// RUN: fir-opt --cg-rewrite %s -o - | FileCheck %s --check-prefixes NODECL5 6 7func.func @test(%arg0: !fir.ref<!fir.array<12x23xi32>>) {8 %c-1 = arith.constant -1 : index9 %c12 = arith.constant 12 : index10 %c-2 = arith.constant -2 : index11 %c23 = arith.constant 23 : index12 %0 = fir.shape_shift %c12, %c-1, %c23, %c-2 : (index, index, index, index) -> !fir.shapeshift<2>13 %1 = fir.declare %arg0(%0) {uniq_name = "_QFarray_numeric_lboundsEx"} : (!fir.ref<!fir.array<12x23xi32>>, !fir.shapeshift<2>) -> !fir.ref<!fir.array<12x23xi32>>14 fir.call @bar(%1) : (!fir.ref<!fir.array<12x23xi32>>) -> ()15 return16}17func.func private @bar(%arg0: !fir.ref<!fir.array<12x23xi32>>)18 19 20// NODECL-LABEL: func.func @test(21// NODECL-SAME: %[[arg0:.*]]: !fir.ref<!fir.array<12x23xi32>>) {22// NODECL-NEXT: fir.call @bar(%[[arg0]]) : (!fir.ref<!fir.array<12x23xi32>>) -> ()23 24// DECL-LABEL: func.func @test(25// DECL-SAME: %[[arg0:.*]]: !fir.ref<!fir.array<12x23xi32>>) {26// DECL: fircg.ext_declare27 28 29func.func @useless_shape_with_duplicate_extent_operand(%arg0: !fir.ref<!fir.array<3x3xf32>>) {30 %c3 = arith.constant 3 : index31 %1 = fir.shape %c3, %c3 : (index, index) -> !fir.shape<2>32 %2 = fir.declare %arg0(%1) {uniq_name = "u"} : (!fir.ref<!fir.array<3x3xf32>>, !fir.shape<2>) -> !fir.ref<!fir.array<3x3xf32>>33 return34}35 36// NODECL-LABEL: func.func @useless_shape_with_duplicate_extent_operand(37// NODECL-NEXT: return38 39// DECL-LABEL: func.func @useless_shape_with_duplicate_extent_operand(40// DECL: fircg.ext_declare41 42// Test DCE does not crash because of unreachable code.43func.func @unreachable_code(%arg0: !fir.ref<!fir.char<1,10>>) {44 %c10 = arith.constant 10 : index45 %2 = fir.declare %arg0 typeparams %c10 {uniq_name = "live_code"} : (!fir.ref<!fir.char<1,10>>, index) -> (!fir.ref<!fir.char<1,10>>)46 return47^bb2: // no predecessors48 %3 = fir.declare %arg0 typeparams %c10 {uniq_name = "dead_code"} : (!fir.ref<!fir.char<1,10>>, index) -> (!fir.ref<!fir.char<1,10>>)49 fir.unreachable50}51// NODECL-LABEL: func.func @unreachable_code(52// NODECL-NOT: uniq_name = "live_code"53// DECL-LABEL: func.func @unreachable_code(54// DECL: uniq_name = "live_code"55 56// Test that storage and storage_offset operands are preserved during conversion57func.func @test_storage_operands() {58 %c0 = arith.constant 0 : index59 %c4 = arith.constant 4 : index60 %0 = fir.address_of(@common_block) : !fir.ref<!fir.array<8xi8>>61 %1 = fir.coordinate_of %0, %c0 : (!fir.ref<!fir.array<8xi8>>, index) -> !fir.ref<i8>62 %2 = fir.convert %1 : (!fir.ref<i8>) -> !fir.ref<f32>63 %3 = fir.declare %2 storage(%0[0]) {uniq_name = "_QFEx"} : (!fir.ref<f32>, !fir.ref<!fir.array<8xi8>>) -> !fir.ref<f32>64 %4 = fir.coordinate_of %0, %c4 : (!fir.ref<!fir.array<8xi8>>, index) -> !fir.ref<i8>65 %5 = fir.convert %4 : (!fir.ref<i8>) -> !fir.ref<i32>66 %6 = fir.declare %5 storage(%0[4]) {uniq_name = "_QFEy"} : (!fir.ref<i32>, !fir.ref<!fir.array<8xi8>>) -> !fir.ref<i32>67 return68}69fir.global @common_block : !fir.array<8xi8>70 71// DECL-LABEL: func.func @test_storage_operands()72// DECL: %[[STORAGE:.*]] = fir.address_of(@common_block) : !fir.ref<!fir.array<8xi8>>73// DECL: fircg.ext_declare {{.*}} storage(%[[STORAGE]][0]) {uniq_name = "_QFEx"}74// DECL: fircg.ext_declare {{.*}} storage(%[[STORAGE]][4]) {uniq_name = "_QFEy"}75