CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
236 lines
9.3 KiB
MLIR
236 lines
9.3 KiB
MLIR
// RUN: fir-opt %s --allow-unregistered-dialect --mem2reg --split-input-file | FileCheck %s
|
|
|
|
// CHECK-LABEL: func.func @basic() -> i32 {
|
|
// CHECK: %[[CONSTANT_0:.*]] = arith.constant 5 : i32
|
|
// CHECK: return %[[CONSTANT_0]] : i32
|
|
// CHECK: }
|
|
func.func @basic() -> i32 {
|
|
%0 = arith.constant 5 : i32
|
|
%1 = fir.alloca i32
|
|
fir.store %0 to %1 : !fir.ref<i32>
|
|
%2 = fir.load %1 : !fir.ref<i32>
|
|
return %2 : i32
|
|
}
|
|
|
|
// -----
|
|
|
|
// CHECK-LABEL: func.func @default_value() -> i32 {
|
|
// CHECK: %[[UNDEFINED_0:.*]] = fir.undefined i32
|
|
// CHECK: %[[CONSTANT_0:.*]] = arith.constant 5 : i32
|
|
// CHECK: return %[[UNDEFINED_0]] : i32
|
|
// CHECK: }
|
|
func.func @default_value() -> i32 {
|
|
%0 = arith.constant 5 : i32
|
|
%1 = fir.alloca i32
|
|
%2 = fir.load %1 : !fir.ref<i32>
|
|
fir.store %0 to %1 : !fir.ref<i32>
|
|
return %2 : i32
|
|
}
|
|
|
|
// -----
|
|
|
|
// CHECK-LABEL: func.func @basic_float() -> f32 {
|
|
// CHECK: %[[CONSTANT_0:.*]] = arith.constant 5.200000e+00 : f32
|
|
// CHECK: return %[[CONSTANT_0]] : f32
|
|
// CHECK: }
|
|
func.func @basic_float() -> f32 {
|
|
%0 = arith.constant 5.2 : f32
|
|
%1 = fir.alloca f32
|
|
fir.store %0 to %1 : !fir.ref<f32>
|
|
%2 = fir.load %1 : !fir.ref<f32>
|
|
return %2 : f32
|
|
}
|
|
|
|
// -----
|
|
|
|
// CHECK-LABEL: func.func @cycle(
|
|
// CHECK-SAME: %[[ARG0:.*]]: i64,
|
|
// CHECK-SAME: %[[ARG1:.*]]: i1,
|
|
// CHECK-SAME: %[[ARG2:.*]]: i64) {
|
|
// CHECK: cf.cond_br %[[ARG1]], ^bb1(%[[ARG2]] : i64), ^bb2(%[[ARG2]] : i64)
|
|
// CHECK: ^bb1(%[[VAL_0:.*]]: i64):
|
|
// CHECK: "test.use"(%[[VAL_0]]) : (i64) -> ()
|
|
// CHECK: cf.br ^bb2(%[[ARG0]] : i64)
|
|
// CHECK: ^bb2(%[[VAL_1:.*]]: i64):
|
|
// CHECK: cf.br ^bb1(%[[VAL_1]] : i64)
|
|
// CHECK: }
|
|
func.func @cycle(%arg0: i64, %arg1: i1, %arg2: i64) {
|
|
%alloca = fir.alloca i64
|
|
fir.store %arg2 to %alloca : !fir.ref<i64>
|
|
cf.cond_br %arg1, ^bb1, ^bb2
|
|
^bb1:
|
|
%use = fir.load %alloca : !fir.ref<i64>
|
|
"test.use"(%use) : (i64) -> ()
|
|
fir.store %arg0 to %alloca : !fir.ref<i64>
|
|
cf.br ^bb2
|
|
^bb2:
|
|
cf.br ^bb1
|
|
}
|
|
|
|
// -----
|
|
|
|
// CHECK-LABEL: func.func @test_simple_declare(%arg0: !fir.ref<i32> {fir.bindc_name = "i"}) {
|
|
// CHECK: %[[C42:.*]] = arith.constant 42 : i32
|
|
// CHECK: %[[SCOPE:.*]] = fir.dummy_scope : !fir.dscope
|
|
// CHECK: %[[ARG_DECL:.*]] = fir.declare %arg0 dummy_scope %[[SCOPE]] arg 1 {uniq_name = "_QFfooEi"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
|
|
// CHECK: fir.declare_value %[[C42]] {uniq_name = "_QFfooEj"} : i32
|
|
// CHECK: fir.store %[[C42]] to %[[ARG_DECL]] : !fir.ref<i32>
|
|
func.func @test_simple_declare(%arg0: !fir.ref<i32> {fir.bindc_name = "i"}) {
|
|
%c42_i32 = arith.constant 42 : i32
|
|
%0 = fir.dummy_scope : !fir.dscope
|
|
%1 = fir.declare %arg0 dummy_scope %0 arg 1 {uniq_name = "_QFfooEi"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
|
|
%2 = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFfooEj"}
|
|
%3 = fir.declare %2 {uniq_name = "_QFfooEj"} : (!fir.ref<i32>) -> !fir.ref<i32>
|
|
fir.store %c42_i32 to %3 : !fir.ref<i32>
|
|
%4 = fir.load %3 : !fir.ref<i32>
|
|
fir.store %4 to %1 : !fir.ref<i32>
|
|
return
|
|
}
|
|
|
|
// -----
|
|
|
|
// CHECK-LABEL: func.func @test_two_values(
|
|
// CHECK: %[[CONSTANT_0:.*]] = arith.constant 43 : i32
|
|
// CHECK: %[[CONSTANT_1:.*]] = arith.constant 42 : i32
|
|
// CHECK: fir.declare_value %[[CONSTANT_1]] {uniq_name = "_QFfooEjlocal"} : i32
|
|
// CHECK: fir.store %[[CONSTANT_1]] to %{{.*}} : !fir.ref<i32>
|
|
// CHECK: fir.declare_value %[[CONSTANT_0]] {uniq_name = "_QFfooEjlocal"} : i32
|
|
// CHECK: fir.store %[[CONSTANT_0]] to %{{.*}} : !fir.ref<i32>
|
|
|
|
func.func @test_two_values(%arg0: !fir.ref<i32> {fir.bindc_name = "i"}, %arg1: !fir.ref<i32> {fir.bindc_name = "j"}) {
|
|
%c43_i32 = arith.constant 43 : i32
|
|
%c42_i32 = arith.constant 42 : i32
|
|
%0 = fir.dummy_scope : !fir.dscope
|
|
%1 = fir.declare %arg0 dummy_scope %0 arg 1 {uniq_name = "_QFfooEi"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
|
|
%2 = fir.declare %arg1 dummy_scope %0 arg 2 {uniq_name = "_QFfooEj"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
|
|
%3 = fir.alloca i32 {bindc_name = "jlocal", uniq_name = "_QFfooEjlocal"}
|
|
%4 = fir.declare %3 {uniq_name = "_QFfooEjlocal"} : (!fir.ref<i32>) -> !fir.ref<i32>
|
|
fir.store %c42_i32 to %4 : !fir.ref<i32>
|
|
%5 = fir.load %4 : !fir.ref<i32>
|
|
fir.store %5 to %1 : !fir.ref<i32>
|
|
fir.store %c43_i32 to %4 : !fir.ref<i32>
|
|
%6 = fir.load %4 : !fir.ref<i32>
|
|
fir.store %6 to %2 : !fir.ref<i32>
|
|
return
|
|
}
|
|
|
|
// -----
|
|
|
|
// CHECK-LABEL: func.func @array_val_not_mem2reg(
|
|
// CHECK: fir.alloca !fir.array<2xi32>
|
|
// CHECK: fir.store
|
|
// CHECK: fir.load
|
|
// CHECK: fir.store
|
|
|
|
func.func @array_val_not_mem2reg(%arg0: !fir.ref<!fir.array<2xi32>> {fir.bindc_name = "i"}, %arg1: !fir.ref<i32> {fir.bindc_name = "j"}, %arrayval : !fir.array<2xi32>) {
|
|
%c2 = arith.constant 2 : index
|
|
%0 = fir.dummy_scope : !fir.dscope
|
|
%1 = fir.shape %c2 : (index) -> !fir.shape<1>
|
|
%2 = fir.declare %arg0(%1) dummy_scope %0 arg 1 {uniq_name = "_QFarrayEi"} : (!fir.ref<!fir.array<2xi32>>, !fir.shape<1>, !fir.dscope) -> !fir.ref<!fir.array<2xi32>>
|
|
%3 = fir.declare %arg1 dummy_scope %0 arg 2 {uniq_name = "_QFarrayEj"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
|
|
%4 = fir.alloca !fir.array<2xi32> {bindc_name = "jlocal", uniq_name = "_QFarrayEjlocal"}
|
|
%5 = fir.declare %4(%1) {uniq_name = "_QFarrayEjlocal"} : (!fir.ref<!fir.array<2xi32>>, !fir.shape<1>) -> !fir.ref<!fir.array<2xi32>>
|
|
fir.store %arrayval to %5 : !fir.ref<!fir.array<2xi32>>
|
|
%val_load = fir.load %5 : !fir.ref<!fir.array<2xi32>>
|
|
fir.store %val_load to %2 : !fir.ref<!fir.array<2xi32>>
|
|
return
|
|
}
|
|
|
|
// -----
|
|
|
|
// CHECK-LABEL: func.func @box_not_mem2reg(
|
|
// CHECK: fir.alloca !fir.box<f32>
|
|
// CHECK: fir.store
|
|
// CHECK: fir.load
|
|
// CHECK: fir.store
|
|
|
|
func.func @box_not_mem2reg(%arg0: !fir.ref<!fir.box<f32>> {fir.bindc_name = "i"}, %arg1: !fir.ref<i32> {fir.bindc_name = "j"}, %arrayval : !fir.box<f32>) {
|
|
%0 = fir.dummy_scope : !fir.dscope
|
|
%2 = fir.declare %arg0 dummy_scope %0 arg 1 {uniq_name = "_QFarrayEi"} : (!fir.ref<!fir.box<f32>>, !fir.dscope) -> !fir.ref<!fir.box<f32>>
|
|
%3 = fir.declare %arg1 dummy_scope %0 arg 2 {uniq_name = "_QFarrayEj"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
|
|
%4 = fir.alloca !fir.box<f32> {bindc_name = "jlocal", uniq_name = "_QFarrayEjlocal"}
|
|
%5 = fir.declare %4 {uniq_name = "_QFarrayEjlocal"} : (!fir.ref<!fir.box<f32>>) -> !fir.ref<!fir.box<f32>>
|
|
fir.store %arrayval to %5 : !fir.ref<!fir.box<f32>>
|
|
%val_load = fir.load %5 : !fir.ref<!fir.box<f32>>
|
|
fir.store %val_load to %2 : !fir.ref<!fir.box<f32>>
|
|
return
|
|
}
|
|
|
|
// -----
|
|
|
|
// Conditional store in a different block through fir.declare is not promoted
|
|
// because MLIR mem2reg would not place the needed phi nodes correctly.
|
|
|
|
// CHECK-LABEL: func.func @block_argument_value(
|
|
// CHECK-SAME: %[[ARG0:.*]]: i32,
|
|
// CHECK-SAME: %[[ARG1:.*]]: i1) -> i32 {
|
|
// CHECK: fir.alloca i32
|
|
// CHECK: fir.declare
|
|
// CHECK: fir.store
|
|
// CHECK: fir.store
|
|
// CHECK: fir.load
|
|
func.func @block_argument_value(%arg0: i32, %cdt: i1) -> i32 {
|
|
%c42_i32 = arith.constant 42 : i32
|
|
%3 = fir.alloca i32 {bindc_name = "jlocal", uniq_name = "_QFfooEjlocal"}
|
|
%4 = fir.declare %3 {uniq_name = "_QFfooEjlocal"} : (!fir.ref<i32>) -> !fir.ref<i32>
|
|
fir.store %c42_i32 to %4 : !fir.ref<i32>
|
|
llvm.cond_br %cdt, ^bb1, ^bb2
|
|
^bb1:
|
|
fir.store %arg0 to %4 : !fir.ref<i32>
|
|
llvm.br ^bb2
|
|
^bb2:
|
|
%6 = fir.load %4 : !fir.ref<i32>
|
|
return %6 : i32
|
|
}
|
|
|
|
// -----
|
|
|
|
// Conditional store inside a loop through fir.declare must not be promoted.
|
|
// MLIR's mem2reg does not register stores through declares as defining blocks,
|
|
// so phi nodes at the loop header would be missing, losing the update.
|
|
|
|
// CHECK-LABEL: func.func @loop_conditional_update(
|
|
// CHECK-SAME: %[[ARG0:.*]]: i32,
|
|
// CHECK-SAME: %[[ARG1:.*]]: i1) -> i32 {
|
|
// CHECK: fir.alloca i32
|
|
// CHECK: fir.declare
|
|
// CHECK: fir.store
|
|
// CHECK: fir.load
|
|
// CHECK: fir.store
|
|
// CHECK: fir.load
|
|
func.func @loop_conditional_update(%arg0: i32, %cdt: i1) -> i32 {
|
|
%c1 = arith.constant 1 : i32
|
|
%alloca = fir.alloca i32 {bindc_name = "mywatch", uniq_name = "_QFkernelEmywatch"}
|
|
%declare = fir.declare %alloca {uniq_name = "_QFkernelEmywatch"} : (!fir.ref<i32>) -> !fir.ref<i32>
|
|
fir.store %arg0 to %declare : !fir.ref<i32>
|
|
llvm.br ^loop
|
|
^loop:
|
|
%val = fir.load %declare : !fir.ref<i32>
|
|
llvm.cond_br %cdt, ^update, ^exit
|
|
^update:
|
|
%new = arith.subi %val, %c1 : i32
|
|
fir.store %new to %declare : !fir.ref<i32>
|
|
llvm.br ^loop
|
|
^exit:
|
|
%result = fir.load %declare : !fir.ref<i32>
|
|
return %result : i32
|
|
}
|
|
|
|
// -----
|
|
|
|
// Make sure we do not generate fir.declare_value for a replaced value
|
|
// fir.declare with dummy_scope. This can result in the declare_value being
|
|
// inserted before the dummy_scope it uses as would be the case here.
|
|
|
|
// CHECK-LABEL: func.func @dummy_scope(
|
|
// CHECK-NOT: fir.declare_value
|
|
func.func @dummy_scope(%arg : i32) {
|
|
%alloca = fir.alloca i32 {adapt.valuebyref}
|
|
fir.store %arg to %alloca : !fir.ref<i32>
|
|
%scope = fir.dummy_scope : !fir.dscope
|
|
%declare = fir.declare %alloca dummy_scope %scope arg 1 {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "foo"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32>
|
|
%result = fir.load %declare : !fir.ref<i32>
|
|
fir.call @use(%result) : (i32) -> ()
|
|
return
|
|
}
|