Skip to content

[flang] Enable delayed localization by default for do concurrent #144074

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

Merged
merged 1 commit into from
Jun 17, 2025

Conversation

ergawy
Copy link
Member

@ergawy ergawy commented Jun 13, 2025

Reintroduces changes from #143897. A fix for the reported problem in #143897 is hopefully resolved in #144027.

This PR aims to make it easier and more self-contained to revert the switch/flag if we discover any problems with enabling it by default.

Reintroduces changes from
#143897. A fix for the
reported problem in #143897
is hopefully resolved in
#144027.

This PR aims to make it easier and more self-contained to revert the
switch/flag if we discover any problems with enabling it by default.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Jun 13, 2025
@ergawy ergawy requested a review from jeanPerier June 13, 2025 13:26
@llvmbot
Copy link
Member

llvmbot commented Jun 13, 2025

@llvm/pr-subscribers-flang-fir-hlfir

Author: Kareem Ergawy (ergawy)

Changes

Reintroduces changes from #143897. A fix for the reported problem in #143897 is hopefully resolved in #144027.

This PR aims to make it easier and more self-contained to revert the switch/flag if we discover any problems with enabling it by default.


Full diff: https://github.com/llvm/llvm-project/pull/144074.diff

6 Files Affected:

  • (modified) flang/lib/Lower/Bridge.cpp (+1-5)
  • (modified) flang/test/Lower/do_concurrent_delayed_locality.f90 (+1-1)
  • (modified) flang/test/Lower/do_concurrent_local_assoc_entity.f90 (+1-1)
  • (modified) flang/test/Lower/do_concurrent_local_default_init.f90 (+1-1)
  • (modified) flang/test/Lower/loops.f90 (+1-1)
  • (modified) flang/test/Lower/loops3.f90 (+1-1)
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 64b16b3abe991..5ff8101dba097 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -2033,11 +2033,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
     fir::LocalitySpecifierOperands privateClauseOps;
     auto doConcurrentLoopOp =
         mlir::dyn_cast_if_present<fir::DoConcurrentLoopOp>(info.loopOp);
-    // TODO Promote to using `enableDelayedPrivatization` (which is enabled by
-    // default unlike the staging flag) once the implementation of this is more
-    // complete.
-    bool useDelayedPriv =
-        enableDelayedPrivatizationStaging && doConcurrentLoopOp;
+    bool useDelayedPriv = enableDelayedPrivatization && doConcurrentLoopOp;
     llvm::SetVector<const Fortran::semantics::Symbol *> allPrivatizedSymbols;
     llvm::SmallSet<const Fortran::semantics::Symbol *, 16> mightHaveReadHostSym;
 
diff --git a/flang/test/Lower/do_concurrent_delayed_locality.f90 b/flang/test/Lower/do_concurrent_delayed_locality.f90
index 6cae0eb46db13..039b17808d19e 100644
--- a/flang/test/Lower/do_concurrent_delayed_locality.f90
+++ b/flang/test/Lower/do_concurrent_delayed_locality.f90
@@ -1,4 +1,4 @@
-! RUN: %flang_fc1 -emit-hlfir -mmlir --enable-delayed-privatization-staging=true -o - %s | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck %s
 
 subroutine do_concurrent_with_locality_specs
   implicit none
diff --git a/flang/test/Lower/do_concurrent_local_assoc_entity.f90 b/flang/test/Lower/do_concurrent_local_assoc_entity.f90
index a3d0c34ed8569..67f080eb2c1c5 100644
--- a/flang/test/Lower/do_concurrent_local_assoc_entity.f90
+++ b/flang/test/Lower/do_concurrent_local_assoc_entity.f90
@@ -1,4 +1,4 @@
-! RUN: %flang_fc1 -emit-hlfir -mmlir --enable-delayed-privatization-staging=true -o - %s | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck %s
 
 subroutine local_assoc
   implicit none
diff --git a/flang/test/Lower/do_concurrent_local_default_init.f90 b/flang/test/Lower/do_concurrent_local_default_init.f90
index d643213854744..798cbb335c8c0 100644
--- a/flang/test/Lower/do_concurrent_local_default_init.f90
+++ b/flang/test/Lower/do_concurrent_local_default_init.f90
@@ -1,5 +1,5 @@
 ! Test default initialization of DO CONCURRENT LOCAL() entities.
-! RUN: bbc -emit-hlfir --enable-delayed-privatization-staging=true -I nowhere -o - %s | FileCheck %s
+! RUN: bbc -emit-hlfir -I nowhere -o - %s | FileCheck %s
 
 subroutine test_ptr(p)
   interface
diff --git a/flang/test/Lower/loops.f90 b/flang/test/Lower/loops.f90
index 60df27a591dc3..64f14ff972272 100644
--- a/flang/test/Lower/loops.f90
+++ b/flang/test/Lower/loops.f90
@@ -1,4 +1,4 @@
-! RUN: bbc -emit-fir -hlfir=false -o - %s | FileCheck %s
+! RUN: bbc -emit-fir -hlfir=false --enable-delayed-privatization=false -o - %s | FileCheck %s
 
 ! CHECK-LABEL: loop_test
 subroutine loop_test
diff --git a/flang/test/Lower/loops3.f90 b/flang/test/Lower/loops3.f90
index 84db1972cca16..34d7bcfb7d7ad 100644
--- a/flang/test/Lower/loops3.f90
+++ b/flang/test/Lower/loops3.f90
@@ -1,5 +1,5 @@
 ! Test do concurrent reduction
-! RUN: bbc -emit-fir -hlfir=false -o - %s | FileCheck %s
+! RUN: bbc -emit-fir -hlfir=false --enable-delayed-privatization=false -o - %s | FileCheck %s
 
 ! CHECK-LABEL: loop_test
 subroutine loop_test

Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, miniWeather worked for me with this patch.

@ergawy ergawy merged commit b5dbf82 into main Jun 17, 2025
10 checks passed
@ergawy ergawy deleted the users/ergawy/reintroduce_dc_dp branch June 17, 2025 04:08
@jeanPerier
Copy link
Contributor

Looks like there is still a gfortran failure in the test suite:

https://lab.llvm.org/buildbot/#/builders/17/builds/8868

FAILED: Fortran/gfortran/regression/CMakeFiles/gfortran-regression-execute-regression__do_concurrent_14_f90.dir/do_concurrent_14.f90.o Fortran/gfortran/regression/gfortran-regression-execute-regression__do_concurrent_14_f90.wd/m.mod 
flang -Illvm-test-suite/Fortran/gfortran/regression -I/proj/scratch/jperier/f18_installs/Linux_x86_64-rome4/llvm-latest/include/flang -Itest-suite-build/Fortran/gfortran/regression/gfortran-regression-execute-regression__do_concurrent_14_f90.wd -O3 -module-dirFortran/gfortran/regression/gfortran-regression-execute-regression__do_concurrent_14_f90.wd -ffixed-line-length-72 -c Fortran/gfortran/regression/CMakeFiles/gfortran-regression-execute-regression__do_concurrent_14_f90.dir/do_concurrent_14.f90-pp.f90 -o Fortran/gfortran/regression/CMakeFiles/gfortran-regression-execute-regression__do_concurrent_14_f90.dir/do_concurrent_14.f90.o
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: flang -fc1 -triple x86_64-unknown-linux-gnu -emit-obj -I llvm-test-suite/Fortran/gfortran/regression -I /proj/scratch/jperier/f18_installs/Linux_x86_64-rome4/llvm-latest/include/flang -I test-suite-build/Fortran/gfortran/regression/gfortran-regression-execute-regression__do_concurrent_14_f90.wd -ffixed-line-length=72 -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -floop-interchange -vectorize-loops -vectorize-slp -fversion-loops-for-stride -module-dir Fortran/gfortran/regression/gfortran-regression-execute-regression__do_concurrent_14_f90.wd -resource-dir /proj/scratch/jperier/f18_installs/Linux_x86_64-rome4/llvm-latest/lib/clang/21 -mframe-pointer=none -O3 -o Fortran/gfortran/regression/CMakeFiles/gfortran-regression-execute-regression__do_concurrent_14_f90.dir/do_concurrent_14.f90.o -x f95 Fortran/gfortran/regression/CMakeFiles/gfortran-regression-execute-regression__do_concurrent_14_f90.dir/do_concurrent_14.f90-pp.f90
 #0 0x0000556e673d51a0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (flang+0x3abe1a0)
 #1 0x0000556e673d25af llvm::sys::RunSignalHandlers() (flang+0x3abb5af)
 #2 0x0000556e673d26fa SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007f2510442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000556e678cde48 mlir::Operation::getRegion(unsigned int) Allocatable.cpp:0:0
 #5 0x0000556e68742708 fir::FirOpBuilder::getAllocaBlock() (flang+0x4e2b708)
 #6 0x0000556e68742a9f fir::FirOpBuilder::createTemporary(mlir::Location, mlir::Type, llvm::StringRef, mlir::ValueRange, mlir::ValueRange, llvm::ArrayRef<mlir::NamedAttribute>, std::optional<Fortran::common::CUDADataAttr>) (flang+0x4e2ba9f)
 #7 0x0000556e684cb2b0 (anonymous namespace)::AssignOpConversion::matchAndRewrite(hlfir::AssignOp, mlir::PatternRewriter&) const ConvertToFIR.cpp:0:0
 #8 0x0000556e6b942b56 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (flang+0x802bb56)
 #9 0x0000556e6b8f8cbc (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0
#10 0x0000556e6b8f8f1c mlir::OperationConverter::convert(mlir::ConversionPatternRewriter&, mlir::Operation*) (flang+0x7fe1f1c)
#11 0x0000556e6b8fb96c mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) (flang+0x7fe496c)
#12 0x0000556e6b8fdfca mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (flang+0x7fe6fca)
#13 0x0000556e684c6df6 (anonymous namespace)::ConvertHLFIRtoFIR::runOnOperation() ConvertToFIR.cpp:0:0
#14 0x0000556e6d149bd9 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (flang+0x9832bd9)
#15 0x0000556e6d14a071 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (flang+0x9833071)
#16 0x0000556e6d14aee9 mlir::PassManager::run(mlir::Operation*) (flang+0x9833ee9)
#17 0x0000556e674355a2 Fortran::frontend::CodeGenAction::generateLLVMIR() (flang+0x3b1e5a2)

ergawy added a commit that referenced this pull request Jun 17, 2025
@ergawy
Copy link
Member Author

ergawy commented Jun 17, 2025

Looks like there is still a gfortran failure in the test suite:

https://lab.llvm.org/buildbot/#/builders/17/builds/8868

FAILED: Fortran/gfortran/regression/CMakeFiles/gfortran-regression-execute-regression__do_concurrent_14_f90.dir/do_concurrent_14.f90.o Fortran/gfortran/regression/gfortran-regression-execute-regression__do_concurrent_14_f90.wd/m.mod 
flang -Illvm-test-suite/Fortran/gfortran/regression -I/proj/scratch/jperier/f18_installs/Linux_x86_64-rome4/llvm-latest/include/flang -Itest-suite-build/Fortran/gfortran/regression/gfortran-regression-execute-regression__do_concurrent_14_f90.wd -O3 -module-dirFortran/gfortran/regression/gfortran-regression-execute-regression__do_concurrent_14_f90.wd -ffixed-line-length-72 -c Fortran/gfortran/regression/CMakeFiles/gfortran-regression-execute-regression__do_concurrent_14_f90.dir/do_concurrent_14.f90-pp.f90 -o Fortran/gfortran/regression/CMakeFiles/gfortran-regression-execute-regression__do_concurrent_14_f90.dir/do_concurrent_14.f90.o
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: flang -fc1 -triple x86_64-unknown-linux-gnu -emit-obj -I llvm-test-suite/Fortran/gfortran/regression -I /proj/scratch/jperier/f18_installs/Linux_x86_64-rome4/llvm-latest/include/flang -I test-suite-build/Fortran/gfortran/regression/gfortran-regression-execute-regression__do_concurrent_14_f90.wd -ffixed-line-length=72 -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -floop-interchange -vectorize-loops -vectorize-slp -fversion-loops-for-stride -module-dir Fortran/gfortran/regression/gfortran-regression-execute-regression__do_concurrent_14_f90.wd -resource-dir /proj/scratch/jperier/f18_installs/Linux_x86_64-rome4/llvm-latest/lib/clang/21 -mframe-pointer=none -O3 -o Fortran/gfortran/regression/CMakeFiles/gfortran-regression-execute-regression__do_concurrent_14_f90.dir/do_concurrent_14.f90.o -x f95 Fortran/gfortran/regression/CMakeFiles/gfortran-regression-execute-regression__do_concurrent_14_f90.dir/do_concurrent_14.f90-pp.f90
 #0 0x0000556e673d51a0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (flang+0x3abe1a0)
 #1 0x0000556e673d25af llvm::sys::RunSignalHandlers() (flang+0x3abb5af)
 #2 0x0000556e673d26fa SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007f2510442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000556e678cde48 mlir::Operation::getRegion(unsigned int) Allocatable.cpp:0:0
 #5 0x0000556e68742708 fir::FirOpBuilder::getAllocaBlock() (flang+0x4e2b708)
 #6 0x0000556e68742a9f fir::FirOpBuilder::createTemporary(mlir::Location, mlir::Type, llvm::StringRef, mlir::ValueRange, mlir::ValueRange, llvm::ArrayRef<mlir::NamedAttribute>, std::optional<Fortran::common::CUDADataAttr>) (flang+0x4e2ba9f)
 #7 0x0000556e684cb2b0 (anonymous namespace)::AssignOpConversion::matchAndRewrite(hlfir::AssignOp, mlir::PatternRewriter&) const ConvertToFIR.cpp:0:0
 #8 0x0000556e6b942b56 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (flang+0x802bb56)
 #9 0x0000556e6b8f8cbc (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0
#10 0x0000556e6b8f8f1c mlir::OperationConverter::convert(mlir::ConversionPatternRewriter&, mlir::Operation*) (flang+0x7fe1f1c)
#11 0x0000556e6b8fb96c mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) (flang+0x7fe496c)
#12 0x0000556e6b8fdfca mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (flang+0x7fe6fca)
#13 0x0000556e684c6df6 (anonymous namespace)::ConvertHLFIRtoFIR::runOnOperation() ConvertToFIR.cpp:0:0
#14 0x0000556e6d149bd9 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (flang+0x9832bd9)
#15 0x0000556e6d14a071 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (flang+0x9833071)
#16 0x0000556e6d14aee9 mlir::PassManager::run(mlir::Operation*) (flang+0x9833ee9)
#17 0x0000556e674355a2 Fortran::frontend::CodeGenAction::generateLLVMIR() (flang+0x3b1e5a2)

Oh boy! Sorry for that. Reverted again and looking into the issue: #144476.

@jeanPerier
Copy link
Contributor

Oh boy! Sorry for that. Reverted again and looking into the issue: #144476.

Thanks, the issue is that builder.getAllocaBlock does not work inside a fir.local. I have not looked futher.

Repro with fir-opt -o - -convert-hlfir-to-fir:

  fir.local {type = local_init} @_QMmFsubEb_firstprivate_box_3xrec__QMmTt : !fir.box<!fir.array<3x!fir.type<_QMmTt{y:i32,ptr:!fir.box<!fir.ptr<!fir.array<?xi32>>>}>>> init {
  ^bb0(%arg0: !fir.ref<!fir.box<!fir.array<3x!fir.type<_QMmTt{y:i32,ptr:!fir.box<!fir.ptr<!fir.array<?xi32>>>}>>>>, %arg1: !fir.ref<!fir.box<!fir.array<3x!fir.type<_QMmTt{y:i32,ptr:!fir.box<!fir.ptr<!fir.array<?xi32>>>}>>>>):
    fir.yield(%arg1 : !fir.ref<!fir.box<!fir.array<3x!fir.type<_QMmTt{y:i32,ptr:!fir.box<!fir.ptr<!fir.array<?xi32>>>}>>>>)
  } copy {
  ^bb0(%arg0: !fir.ref<!fir.box<!fir.array<3x!fir.type<_QMmTt{y:i32,ptr:!fir.box<!fir.ptr<!fir.array<?xi32>>>}>>>>, %arg1: !fir.ref<!fir.box<!fir.array<3x!fir.type<_QMmTt{y:i32,ptr:!fir.box<!fir.ptr<!fir.array<?xi32>>>}>>>>):
    %0 = fir.load %arg0 : !fir.ref<!fir.box<!fir.array<3x!fir.type<_QMmTt{y:i32,ptr:!fir.box<!fir.ptr<!fir.array<?xi32>>>}>>>>
    hlfir.assign %0 to %arg1 : !fir.box<!fir.array<3x!fir.type<_QMmTt{y:i32,ptr:!fir.box<!fir.ptr<!fir.array<?xi32>>>}>>>, !fir.ref<!fir.box<!fir.array<3x!fir.type<_QMmTt{y:i32,ptr:!fir.box<!fir.ptr<!fir.array<?xi32>>>}>>>>
    fir.yield(%arg1 : !fir.ref<!fir.box<!fir.array<3x!fir.type<_QMmTt{y:i32,ptr:!fir.box<!fir.ptr<!fir.array<?xi32>>>}>>>>)
  } dealloc {
  ^bb0(%arg0: !fir.ref<!fir.box<!fir.array<3x!fir.type<_QMmTt{y:i32,ptr:!fir.box<!fir.ptr<!fir.array<?xi32>>>}>>>>):
    fir.yield
  }

ergawy added a commit that referenced this pull request Jun 17, 2025
ajaden-codes pushed a commit to Jaddyen/llvm-project that referenced this pull request Jun 17, 2025
…lvm#144074)

Reintroduces changes from
llvm#143897. A fix for the
reported problem in llvm#143897
is hopefully resolved in
llvm#144027.

This PR aims to make it easier and more self-contained to revert the
switch/flag if we discover any problems with enabling it by default.
ajaden-codes pushed a commit to Jaddyen/llvm-project that referenced this pull request Jun 17, 2025
fschlimb pushed a commit to fschlimb/llvm-project that referenced this pull request Jun 18, 2025
…lvm#144074)

Reintroduces changes from
llvm#143897. A fix for the
reported problem in llvm#143897
is hopefully resolved in
llvm#144027.

This PR aims to make it easier and more self-contained to revert the
switch/flag if we discover any problems with enabling it by default.
fschlimb pushed a commit to fschlimb/llvm-project that referenced this pull request Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants