- Notifications
You must be signed in to change notification settings - Fork 15.3k
[flang] Fixing code reordering in alloca hoist pass. #95610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| @llvm/pr-subscribers-flang-codegen @llvm/pr-subscribers-flang-fir-hlfir Author: Vijay Kandiah (VijayKandiah) ChangesThis change avoids reordering allocas that are already in the proper block which my previous change was doing, and thus fixes the remaining lit test failures. Patch is 20.68 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/95610.diff 7 Files Affected:
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp index 4448224024f20..91ba28220d1d4 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -255,8 +255,10 @@ struct AllocaOpConversion : public fir::FIROpConversion<fir::AllocaOp> { mlir::Region *parentRegion = rewriter.getInsertionBlock()->getParent(); mlir::Block *insertBlock = getBlockForAllocaInsert(parentOp, parentRegion); - size.getDefiningOp()->moveAfter(insertBlock, insertBlock->begin()); - rewriter.setInsertionPointAfter(size.getDefiningOp()); + if (rewriter.getInsertionBlock() != insertBlock) { + size.getDefiningOp()->moveAfter(insertBlock, insertBlock->begin()); + rewriter.setInsertionPointAfter(size.getDefiningOp()); + } } // NOTE: we used to pass alloc->getAttrs() in the builder for non opaque @@ -3705,7 +3707,8 @@ class FIRToLLVMLowering signalPassFailure(); } - // Run pass to add comdats to functions that have weak linkage on relevant platforms + // Run pass to add comdats to functions that have weak linkage on relevant + // platforms if (fir::getTargetTriple(mod).supportsCOMDAT()) { mlir::OpPassManager comdatPM("builtin.module"); comdatPM.addPass(mlir::LLVM::createLLVMAddComdats()); diff --git a/flang/test/Fir/alloc.fir b/flang/test/Fir/alloc.fir index e00fc9d6649c4..cf77fcf8c6988 100644 --- a/flang/test/Fir/alloc.fir +++ b/flang/test/Fir/alloc.fir @@ -334,10 +334,10 @@ func.func @allocmem_array_with_holes_dynchar(%arg0: index, %arg1: index) -> !fir } // CHECK-LABEL: define void @alloca_unlimited_polymorphic_box -// CHECK: %[[VAL_1:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]], ptr, [1 x i64] }, i64 1 // CHECK: %[[VAL_0:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] }, i64 1 -// CHECK: %[[VAL_3:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]], ptr, [1 x i64] }, i64 1 +// CHECK: %[[VAL_1:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]], ptr, [1 x i64] }, i64 1 // CHECK: %[[VAL_2:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, ptr, [1 x i64] }, i64 1 +// CHECK: %[[VAL_3:.*]] = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]], ptr, [1 x i64] }, i64 1 func.func @alloca_unlimited_polymorphic_box() { %0 = fir.alloca !fir.class<none> diff --git a/flang/test/Fir/boxproc.fir b/flang/test/Fir/boxproc.fir index 834017bff71aa..11d11f24d547e 100644 --- a/flang/test/Fir/boxproc.fir +++ b/flang/test/Fir/boxproc.fir @@ -1,12 +1,12 @@ // RUN: tco %s | FileCheck %s // CHECK-LABEL: define void @_QPtest_proc_dummy() -// CHECK: %[[VAL_3:.*]] = alloca [32 x i8], i64 1, align 1 -// CHECK: %[[VAL_1:.*]] = alloca { ptr }, i64 1, align 8 // CHECK: %[[VAL_0:.*]] = alloca i32, i64 1, align 4 +// CHECK: %[[VAL_1:.*]] = alloca { ptr }, i64 1, align 8 // CHECK: %[[VAL_2:.*]] = getelementptr { ptr }, ptr %[[VAL_1]], i32 0, i32 0 // CHECK: store ptr %[[VAL_0]], ptr %[[VAL_2]], align 8 // CHECK: store i32 1, ptr %[[VAL_0]], align 4 +// CHECK: %[[VAL_3:.*]] = alloca [32 x i8], i64 1, align 1 // CHECK: call void @llvm.init.trampoline(ptr %[[VAL_3]], ptr @_QFtest_proc_dummyPtest_proc_dummy_a, ptr %[[VAL_1]]) // CHECK: %[[VAL_6:.*]] = call ptr @llvm.adjust.trampoline(ptr %[[VAL_3]]) // CHECK: call void @_QPtest_proc_dummy_other(ptr %[[VAL_6]]) @@ -62,9 +62,9 @@ func.func @_QPtest_proc_dummy_other(%arg0: !fir.boxproc<() -> ()>) { // CHECK-LABEL: define void @_QPtest_proc_dummy_char() // CHECK: %[[VAL_20:.*]] = alloca [32 x i8], i64 1, align 1 -// CHECK: %[[VAL_2:.*]] = alloca { { ptr, i64 } }, i64 1, align 8 -// CHECK: %[[VAL_1:.*]] = alloca [10 x i8], i64 1, align 1 // CHECK: %[[VAL_0:.*]] = alloca [40 x i8], i64 1, align 1 +// CHECK: %[[VAL_1:.*]] = alloca [10 x i8], i64 1, align 1 +// CHECK: %[[VAL_2:.*]] = alloca { { ptr, i64 } }, i64 1, align 8 // CHECK: %[[VAL_3:.*]] = getelementptr { { ptr, i64 } }, ptr %[[VAL_2]], i32 0, i32 0 // CHECK: %[[VAL_5:.*]] = insertvalue { ptr, i64 } undef, ptr %[[VAL_1]], 0 // CHECK: %[[VAL_6:.*]] = insertvalue { ptr, i64 } %[[VAL_5]], i64 10, 1 diff --git a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir index 45ff89bc40943..6c388f93dcbc5 100644 --- a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir +++ b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir @@ -283,52 +283,52 @@ func.func @_QPomp_target_data() { // CHECK-LABEL: llvm.func @_QPomp_target_data() { // CHECK: %[[VAL_0:.*]] = llvm.mlir.constant(1024 : index) : i64 // CHECK: %[[VAL_1:.*]] = llvm.mlir.constant(1 : i64) : i64 -// CHECK: %[[VAL_2:.*]] = llvm.alloca %[[VAL_1]] x !llvm.array<1024 x i32> {bindc_name = "d"} : (i64) -> !llvm.ptr -// CHECK: %[[VAL_3:.*]] = llvm.mlir.constant(1 : i64) : i64 -// CHECK: %[[VAL_4:.*]] = llvm.alloca %[[VAL_3]] x !llvm.array<1024 x i32> {bindc_name = "c"} : (i64) -> !llvm.ptr -// CHECK: %[[VAL_5:.*]] = llvm.mlir.constant(1 : i64) : i64 -// CHECK: %[[VAL_6:.*]] = llvm.alloca %[[VAL_5]] x !llvm.array<1024 x i32> {bindc_name = "b"} : (i64) -> !llvm.ptr +// CHECK: %[[VAL_2:.*]] = llvm.alloca %[[VAL_1]] x !llvm.array<1024 x i32> {bindc_name = "a"} : (i64) -> !llvm.ptr +// CHECK: %[[VAL_3:.*]] = llvm.mlir.constant(1024 : index) : i64 +// CHECK: %[[VAL_4:.*]] = llvm.mlir.constant(1 : i64) : i64 +// CHECK: %[[VAL_5:.*]] = llvm.alloca %[[VAL_4]] x !llvm.array<1024 x i32> {bindc_name = "b"} : (i64) -> !llvm.ptr +// CHECK: %[[VAL_6:.*]] = llvm.mlir.constant(1024 : index) : i64 // CHECK: %[[VAL_7:.*]] = llvm.mlir.constant(1 : i64) : i64 -// CHECK: %[[VAL_8:.*]] = llvm.alloca %[[VAL_7]] x !llvm.array<1024 x i32> {bindc_name = "a"} : (i64) -> !llvm.ptr +// CHECK: %[[VAL_8:.*]] = llvm.alloca %[[VAL_7]] x !llvm.array<1024 x i32> {bindc_name = "c"} : (i64) -> !llvm.ptr // CHECK: %[[VAL_9:.*]] = llvm.mlir.constant(1024 : index) : i64 -// CHECK: %[[VAL_10:.*]] = llvm.mlir.constant(1024 : index) : i64 -// CHECK: %[[VAL_11:.*]] = llvm.mlir.constant(1024 : index) : i64 +// CHECK: %[[VAL_10:.*]] = llvm.mlir.constant(1 : i64) : i64 +// CHECK: %[[VAL_11:.*]] = llvm.alloca %[[VAL_10]] x !llvm.array<1024 x i32> {bindc_name = "d"} : (i64) -> !llvm.ptr // CHECK: %[[VAL_12:.*]] = llvm.mlir.constant(1 : index) : i64 // CHECK: %[[VAL_13:.*]] = llvm.mlir.constant(0 : index) : i64 // CHECK: %[[VAL_14:.*]] = llvm.mlir.constant(1023 : index) : i64 // CHECK: %[[VAL_15:.*]] = omp.map.bounds lower_bound(%[[VAL_13]] : i64) upper_bound(%[[VAL_14]] : i64) extent(%[[VAL_0]] : i64) stride(%[[VAL_12]] : i64) start_idx(%[[VAL_12]] : i64) -// CHECK: %[[VAL_16:.*]] = omp.map.info var_ptr(%[[VAL_8]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(to) capture(ByRef) bounds(%[[VAL_15]]) -> !llvm.ptr {name = "a"} +// CHECK: %[[VAL_16:.*]] = omp.map.info var_ptr(%[[VAL_2]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(to) capture(ByRef) bounds(%[[VAL_15]]) -> !llvm.ptr {name = "a"} // CHECK: %[[VAL_17:.*]] = llvm.mlir.constant(1 : index) : i64 // CHECK: %[[VAL_18:.*]] = llvm.mlir.constant(0 : index) : i64 // CHECK: %[[VAL_19:.*]] = llvm.mlir.constant(1023 : index) : i64 -// CHECK: %[[VAL_20:.*]] = omp.map.bounds lower_bound(%[[VAL_18]] : i64) upper_bound(%[[VAL_19]] : i64) extent(%[[VAL_9]] : i64) stride(%[[VAL_17]] : i64) start_idx(%[[VAL_17]] : i64) -// CHECK: %[[VAL_21:.*]] = omp.map.info var_ptr(%[[VAL_6]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(to) capture(ByRef) bounds(%[[VAL_20]]) -> !llvm.ptr {name = "b"} +// CHECK: %[[VAL_20:.*]] = omp.map.bounds lower_bound(%[[VAL_18]] : i64) upper_bound(%[[VAL_19]] : i64) extent(%[[VAL_3]] : i64) stride(%[[VAL_17]] : i64) start_idx(%[[VAL_17]] : i64) +// CHECK: %[[VAL_21:.*]] = omp.map.info var_ptr(%[[VAL_5]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(to) capture(ByRef) bounds(%[[VAL_20]]) -> !llvm.ptr {name = "b"} // CHECK: %[[VAL_22:.*]] = llvm.mlir.constant(1 : index) : i64 // CHECK: %[[VAL_23:.*]] = llvm.mlir.constant(0 : index) : i64 // CHECK: %[[VAL_24:.*]] = llvm.mlir.constant(1023 : index) : i64 -// CHECK: %[[VAL_25:.*]] = omp.map.bounds lower_bound(%[[VAL_23]] : i64) upper_bound(%[[VAL_24]] : i64) extent(%[[VAL_10]] : i64) stride(%[[VAL_22]] : i64) start_idx(%[[VAL_22]] : i64) -// CHECK: %[[VAL_26:.*]] = omp.map.info var_ptr(%[[VAL_4]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(always, exit_release_or_enter_alloc) capture(ByRef) bounds(%[[VAL_25]]) -> !llvm.ptr {name = "c"} +// CHECK: %[[VAL_25:.*]] = omp.map.bounds lower_bound(%[[VAL_23]] : i64) upper_bound(%[[VAL_24]] : i64) extent(%[[VAL_6]] : i64) stride(%[[VAL_22]] : i64) start_idx(%[[VAL_22]] : i64) +// CHECK: %[[VAL_26:.*]] = omp.map.info var_ptr(%[[VAL_8]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(always, exit_release_or_enter_alloc) capture(ByRef) bounds(%[[VAL_25]]) -> !llvm.ptr {name = "c"} // CHECK: omp.target_enter_data map_entries(%[[VAL_16]], %[[VAL_21]], %[[VAL_26]] : !llvm.ptr, !llvm.ptr, !llvm.ptr) // CHECK: %[[VAL_27:.*]] = llvm.mlir.constant(1 : index) : i64 // CHECK: %[[VAL_28:.*]] = llvm.mlir.constant(0 : index) : i64 // CHECK: %[[VAL_29:.*]] = llvm.mlir.constant(1023 : index) : i64 // CHECK: %[[VAL_30:.*]] = omp.map.bounds lower_bound(%[[VAL_28]] : i64) upper_bound(%[[VAL_29]] : i64) extent(%[[VAL_0]] : i64) stride(%[[VAL_27]] : i64) start_idx(%[[VAL_27]] : i64) -// CHECK: %[[VAL_31:.*]] = omp.map.info var_ptr(%[[VAL_8]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(from) capture(ByRef) bounds(%[[VAL_30]]) -> !llvm.ptr {name = "a"} +// CHECK: %[[VAL_31:.*]] = omp.map.info var_ptr(%[[VAL_2]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(from) capture(ByRef) bounds(%[[VAL_30]]) -> !llvm.ptr {name = "a"} // CHECK: %[[VAL_32:.*]] = llvm.mlir.constant(1 : index) : i64 // CHECK: %[[VAL_33:.*]] = llvm.mlir.constant(0 : index) : i64 // CHECK: %[[VAL_34:.*]] = llvm.mlir.constant(1023 : index) : i64 -// CHECK: %[[VAL_35:.*]] = omp.map.bounds lower_bound(%[[VAL_33]] : i64) upper_bound(%[[VAL_34]] : i64) extent(%[[VAL_9]] : i64) stride(%[[VAL_32]] : i64) start_idx(%[[VAL_32]] : i64) -// CHECK: %[[VAL_36:.*]] = omp.map.info var_ptr(%[[VAL_6]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(from) capture(ByRef) bounds(%[[VAL_35]]) -> !llvm.ptr {name = "b"} +// CHECK: %[[VAL_35:.*]] = omp.map.bounds lower_bound(%[[VAL_33]] : i64) upper_bound(%[[VAL_34]] : i64) extent(%[[VAL_3]] : i64) stride(%[[VAL_32]] : i64) start_idx(%[[VAL_32]] : i64) +// CHECK: %[[VAL_36:.*]] = omp.map.info var_ptr(%[[VAL_5]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(from) capture(ByRef) bounds(%[[VAL_35]]) -> !llvm.ptr {name = "b"} // CHECK: %[[VAL_37:.*]] = llvm.mlir.constant(1 : index) : i64 // CHECK: %[[VAL_38:.*]] = llvm.mlir.constant(0 : index) : i64 // CHECK: %[[VAL_39:.*]] = llvm.mlir.constant(1023 : index) : i64 -// CHECK: %[[VAL_40:.*]] = omp.map.bounds lower_bound(%[[VAL_38]] : i64) upper_bound(%[[VAL_39]] : i64) extent(%[[VAL_10]] : i64) stride(%[[VAL_37]] : i64) start_idx(%[[VAL_37]] : i64) -// CHECK: %[[VAL_41:.*]] = omp.map.info var_ptr(%[[VAL_4]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(exit_release_or_enter_alloc) capture(ByRef) bounds(%[[VAL_40]]) -> !llvm.ptr {name = "c"} +// CHECK: %[[VAL_40:.*]] = omp.map.bounds lower_bound(%[[VAL_38]] : i64) upper_bound(%[[VAL_39]] : i64) extent(%[[VAL_6]] : i64) stride(%[[VAL_37]] : i64) start_idx(%[[VAL_37]] : i64) +// CHECK: %[[VAL_41:.*]] = omp.map.info var_ptr(%[[VAL_8]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(exit_release_or_enter_alloc) capture(ByRef) bounds(%[[VAL_40]]) -> !llvm.ptr {name = "c"} // CHECK: %[[VAL_42:.*]] = llvm.mlir.constant(1 : index) : i64 // CHECK: %[[VAL_43:.*]] = llvm.mlir.constant(0 : index) : i64 // CHECK: %[[VAL_44:.*]] = llvm.mlir.constant(1023 : index) : i64 -// CHECK: %[[VAL_45:.*]] = omp.map.bounds lower_bound(%[[VAL_43]] : i64) upper_bound(%[[VAL_44]] : i64) extent(%[[VAL_11]] : i64) stride(%[[VAL_42]] : i64) start_idx(%[[VAL_42]] : i64) -// CHECK: %[[VAL_46:.*]] = omp.map.info var_ptr(%[[VAL_2]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(always, delete) capture(ByRef) bounds(%[[VAL_45]]) -> !llvm.ptr {name = "d"} +// CHECK: %[[VAL_45:.*]] = omp.map.bounds lower_bound(%[[VAL_43]] : i64) upper_bound(%[[VAL_44]] : i64) extent(%[[VAL_9]] : i64) stride(%[[VAL_42]] : i64) start_idx(%[[VAL_42]] : i64) +// CHECK: %[[VAL_46:.*]] = omp.map.info var_ptr(%[[VAL_11]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(always, delete) capture(ByRef) bounds(%[[VAL_45]]) -> !llvm.ptr {name = "d"} // CHECK: omp.target_exit_data map_entries(%[[VAL_31]], %[[VAL_36]], %[[VAL_41]], %[[VAL_46]] : !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr) // CHECK: llvm.return // CHECK: } @@ -374,9 +374,9 @@ func.func @_QPopenmp_target_data_region() { // CHECK-LABEL: llvm.func @_QPopenmp_target_data_region() { // CHECK: %[[VAL_0:.*]] = llvm.mlir.constant(1 : i64) : i64 +// CHECK: %[[VAL_1:.*]] = llvm.alloca %[[VAL_0]] x !llvm.array<1024 x i32> {bindc_name = "a"} : (i64) -> !llvm.ptr // CHECK: %[[VAL_2:.*]] = llvm.mlir.constant(1 : i64) : i64 // CHECK: %[[VAL_3:.*]] = llvm.alloca %[[VAL_2]] x i32 {bindc_name = "i"} : (i64) -> !llvm.ptr -// CHECK: %[[VAL_1:.*]] = llvm.alloca %[[VAL_0]] x !llvm.array<1024 x i32> {bindc_name = "a"} : (i64) -> !llvm.ptr // CHECK: %[[VAL_MAX:.*]] = llvm.mlir.constant(1024 : index) : i64 // CHECK: %[[VAL_ONE:.*]] = llvm.mlir.constant(1 : index) : i64 // CHECK: %[[VAL_ZERO:.*]] = llvm.mlir.constant(0 : index) : i64 @@ -675,9 +675,10 @@ func.func @_QPsb() { } // CHECK: llvm.func @_QPsb() { +// CHECK: %[[ONE:.*]] = llvm.mlir.constant(1 : i32) : i32 +// CHECK: %[[TWO:.*]] = llvm.mlir.constant(1 : i64) : i64 // CHECK: %[[SIZE:.*]] = llvm.mlir.constant(1 : i64) : i64 // CHECK: %[[LI_REF:.*]] = llvm.alloca %[[SIZE]] x i32 {bindc_name = "li"} : (i64) -> !llvm.ptr -// CHECK: %[[ONE:.*]] = llvm.mlir.constant(1 : i32) : i32 // CHECK: omp.sections { // CHECK: omp.section { // CHECK: llvm.br ^[[BB_ENTRY:.*]]({{.*}}) @@ -715,7 +716,7 @@ func.func @_QPsb() { // CHECK: } // CHECK-LABEL: @_QPsimple_reduction // CHECK-SAME: %[[ARRAY_REF:.*]]: !llvm.ptr -// CHECK: %[[RED_ACCUMULATOR:.*]] = llvm.alloca %1 x i32 {bindc_name = "x"} : (i64) -> !llvm.ptr +// CHECK: %[[RED_ACCUMULATOR:.*]] = llvm.alloca %2 x i32 {bindc_name = "x"} : (i64) -> !llvm.ptr // CHECK: omp.parallel { // CHECK: omp.wsloop reduction(@[[EQV_REDUCTION]] %[[RED_ACCUMULATOR]] -> %[[PRV:.+]] : !llvm.ptr) { // CHECK-NEXT: omp.loop_nest @@ -797,7 +798,6 @@ func.func @_QPs(%arg0: !fir.ref<!fir.complex<4>> {fir.bindc_name = "x"}) { // Test if llvm.alloca is properly inserted in the omp section -//CHECK: %[[CONST0:.*]] = llvm.mlir.constant(1 : i64) : i64 //CHECK: %[[CONST:.*]] = llvm.mlir.constant(1 : i64) : i64 //CHECK: %[[ALLOCA:.*]] = llvm.alloca %[[CONST]] x !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)> {bindc_name = "iattr"} : (i64) -> !llvm.ptr //CHECK: omp.parallel { @@ -908,9 +908,9 @@ omp.critical.declare @help hint(contended) // CHECK: llvm.func @omp_critical_() { func.func @omp_critical_() { -// CHECK: %[[Y_REF:.*]] = llvm.alloca %{{.*}} x i32 {bindc_name = "y"} : (i64) -> !llvm.ptr - %0 = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFomp_criticalEx"} // CHECK: %[[X_REF:.*]] = llvm.alloca %{{.*}} x i32 {bindc_name = "x"} : (i64) -> !llvm.ptr + %0 = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFomp_criticalEx"} +// CHECK: %[[Y_REF:.*]] = llvm.alloca %{{.*}} x i32 {bindc_name = "y"} : (i64) -> !llvm.ptr %1 = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFomp_criticalEy"} // CHECK: omp.critical(@help) omp.critical(@help) { diff --git a/flang/test/Fir/convert-to-llvm.fir b/flang/test/Fir/convert-to-llvm.fir index d7059671d3a88..217bfc120e572 100644 --- a/flang/test/Fir/convert-to-llvm.fir +++ b/flang/test/Fir/convert-to-llvm.fir @@ -2015,17 +2015,17 @@ func.func private @_QPtest_dt_callee(%arg0: !fir.box<!fir.array<?xi32>>) // AMDGPU: %[[AA:.*]] = llvm.alloca %[[ALLOCA_SIZE]] x !llvm.struct<(ptr, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, array<1 x array<3 x i64>>)> {alignment = 8 : i64} : (i32) -> !llvm.ptr<5> // AMDGPU: %[[ALLOCA:.*]] = llvm.addrspacecast %[[AA]] : !llvm.ptr<5> to !llvm.ptr // CHECK: %[[C20:.*]] = llvm.mlir.constant(20 : index) : i64 -// CHECK: %[[ALLOCA_SIZE_X:.*]] = llvm.mlir.constant(1 : i64) : i64 -// GENERIC: %[[X:.*]] = llvm.alloca %[[ALLOCA_SIZE_X]] x !llvm.array<20 x struct<"_QFtest_dt_sliceTt", (i32, i32)>> {bindc_name = "x"} : (i64) -> !llvm.ptr -// AMDGPU: %[[AC:.*]] = llvm.alloca %[[ALLOCA_SIZE_X]] x !llvm.array<20 x struct<"_QFtest_dt_sliceTt", (i32, i32)>> {bindc_name = "x"} : (i64) -> !llvm.ptr<5> -// AMDGPU: %[[X:.*]] = llvm.addrspacecast %[[AC]] : !llvm.ptr<5> to !llvm.ptr +// CHECK: %[[C1:.*]] = llvm.mlir.constant(1 : i64) : i64 +// CHECK: %[[C10:.*]] = llvm.mlir.constant(10 : i64) : i64 +// CHECK: %[[C2:.*]] = llvm.mlir.constant(2 : i64) : i64 // CHECK: %[[ALLOCA_SIZE_V:.*]] = llvm.mlir.constant(1 : i64) : i64 // GENERIC: %[[V:.*]] = llvm.alloca %[[ALLOCA_SIZE_V]] x i32 {bindc_name = "v"} : (i64) -> !llvm.ptr // AMDGPU: %[[AB:.*]] = llvm.alloca %[[ALLOCA_SIZE_V]] x i32 {bindc_name = "v"} : (i64) -> !llvm.ptr<5> // AMDGPU: %[[V:.*]] = llvm.addrspacecast %[[AB]] : !llvm.ptr<5> to !llvm.ptr -// CHECK: %[[C1:.*]] = llvm.mlir.constant(1 : i64) : i64 -// CHECK: %[[C10:.*]] = llvm.mlir.constant(10 : i64) : i64 -// CHECK: %[[C2:.*]] = llvm.mlir.constant(2 : i64) : i64 +// CHECK: %[[ALLOCA_SIZE_X:.*]] = llvm.mlir.constant(1 : i64) : i64 +// GENERIC: %[[X:.*]] = llvm.alloca %[[ALLOCA_SIZE_X]] x !llvm.array<20 x struct<"_QFtest_dt_sliceTt", (i32, i32)>> {bindc_name = "x"} : (i64) -> !llvm.ptr +// AMDGPU: %[[AC:.*]] = llvm.alloca %[[ALLOCA_SIZE_X]] x !llvm.array<20 x struct<"_QFtest_dt_sliceTt", (i32, i32)>> {bindc_name = "x"} : (i64) -> !llvm.ptr<5> +// AMDGPU: %[[X:.*]] = llvm.addrspacecast %[[AC]] : !llvm.ptr<5> to !llvm.ptr // CHECK: %[[TYPE_CODE:.*]] = llvm.mlir.constant(9 : i32) : i32 // CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr // CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1] diff --git a/flang/test/Integration/OpenMP/copyprivate.f90 b/flang/test/Integration/OpenMP/copyprivate.f90 index dd69ebdb881a1..d32319a18c28b 100644 --- a/flang/test/Integration/OpenMP/copyprivate.f90 +++ b/flang/test/Integration/OpenMP/copyprivate.f90 @@ -33,8 +33,8 @@ !CHECK-NEXT: } !CHECK-LABEL: define internal void @test_scalar_..omp_par({{.*}}) -!CHECK: %[[J:.*]] = alloca i32, i64 1 !CHECK: %[[I:.*]] = alloca i32, i64 1 +!CHECK: %[[J:.*]] = alloca i32, i64 1 !CHECK: %[[DID_IT:.*]] = alloca i32 !CHECK: store i32 0, ptr %[[DID_IT]] !CHECK: %[[THREAD_NUM1:.*]] = call i32 @__kmpc_global_thread_num(ptr @[[LOC:.*]]) diff --git a/flang/test/Transforms/debug-local-var-2.f90 b/flang/test/Transforms/debug-local-var-2.f90 index 79fe1bab6e35b..ce78bfd005056 100644 --- a/flang/test/Transforms/debug-local-var-2.f90 +++ b/flang/test/Transforms/debug-local-var-2.f90 @@ -6,12 +6,12 @@ ! This tests checks the debug information for local variables in llvm IR. ! BOTH-LABEL: define void @_QQmain -! BOTH-DAG: %[[AL16:.*]] = alloca double -! BOTH-DAG: %[[AL15:.*]] = alloca float -! BOTH-DAG: ... [truncated] |
| getBlockForAllocaInsert(parentOp, parentRegion); | ||
| size.getDefiningOp()->moveAfter(insertBlock, insertBlock->begin()); | ||
| rewriter.setInsertionPointAfter(size.getDefiningOp()); | ||
| if (rewriter.getInsertionBlock() != insertBlock) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems okay, but I think there might be cases where we will leave the allocas inside stacksave/stackrestore region (which the initial commit tried to avoid). I am okay with this change to resolve the LIT tests failures, but we may need to revisit this (and fix the tests, if needed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. We would need to revisit to move allocas outside stacksave/restore regions + fix lit tests as necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, I think we would prefer to fix the remaining tests (5 powerpc tests) instead of making another codegen change. I'll go fix those and create a separate merge request to get rid of those lit test failures.
This change avoids reordering allocas that are already in the proper block which my previous change was doing, and thus fixes the remaining lit test failures.