[flang-commits] [flang] [llvm] [OpenMP][][LLVM] Update alloca IP after `PrivCB` in `OMPIRBUIlder` (PR #93920)
via flang-commits
flang-commits at lists.llvm.org
Thu May 30 21:44:24 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-openmp
Author: Kareem Ergawy (ergawy)
<details>
<summary>Changes</summary>
Fixes a crash uncovered by [pr77666.f90](https://github.com/llvm/llvm-test-suite/blob/main/Fortran/gfortran/regression/gomp/pr77666.f90) in the test suite.
In particular, whenever `PrivCB` (the callback responsible for generating privatizaiton logic for an OMP variable) generates a multi-block privatization region, the insertion point diverges: the BB component of the IP can become a different BB from the parent block of the instruction iterator component of the IP. This PR updates the IP to make sure that the BB is the parent block of the instruction iterator.
---
Full diff: https://github.com/llvm/llvm-project/pull/93920.diff
2 Files Affected:
- (added) flang/test/Lower/OpenMP/delayed-privatization-lower-allocatable-to-llvm.f90 (+20)
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+3)
``````````diff
diff --git a/flang/test/Lower/OpenMP/delayed-privatization-lower-allocatable-to-llvm.f90 b/flang/test/Lower/OpenMP/delayed-privatization-lower-allocatable-to-llvm.f90
new file mode 100644
index 0000000000000..0363494c59ecf
--- /dev/null
+++ b/flang/test/Lower/OpenMP/delayed-privatization-lower-allocatable-to-llvm.f90
@@ -0,0 +1,20 @@
+! RUN: %flang -S -emit-llvm -fopenmp -mmlir --openmp-enable-delayed-privatization \
+! RUN: -o - %s 2>&1 | FileCheck %s
+
+subroutine foo(x)
+ integer, allocatable :: x, y
+!$omp parallel private(x, y)
+ x = y
+!$omp end parallel
+end
+
+! CHECK-LABEL: define void @foo_
+! CHECK: ret void
+! CHECK-NEXT: }
+
+! CHECK-LABEL: define internal void @foo_..omp_par
+! CHECK-DAG: call ptr @malloc
+! CHECK-DAG: call ptr @malloc
+! CHECK-DAG: call void @free
+! CHECK-DAG: call void @free
+! CHECK: }
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index cb4de9c8876dc..eab41eb8a35b2 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -1583,6 +1583,9 @@ IRBuilder<>::InsertPoint OpenMPIRBuilder::createParallel(
} else {
Builder.restoreIP(
PrivCB(InnerAllocaIP, Builder.saveIP(), V, *Inner, ReplacementValue));
+ InnerAllocaIP = {InnerAllocaIP.getPoint()->getParent(),
+ InnerAllocaIP.getPoint()};
+
assert(ReplacementValue &&
"Expected copy/create callback to set replacement value!");
if (ReplacementValue == &V)
``````````
</details>
https://github.com/llvm/llvm-project/pull/93920
More information about the flang-commits
mailing list