[llvm] 7e77e81 - [Attributor][FIX] Require the store to be aligned for value propagation
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 7 16:39:17 PDT 2023
Author: Johannes Doerfert
Date: 2023-07-07T16:38:34-07:00
New Revision: 7e77e812ab51bd24414665edbaa4707a869708dd
URL: https://github.com/llvm/llvm-project/commit/7e77e812ab51bd24414665edbaa4707a869708dd
DIFF: https://github.com/llvm/llvm-project/commit/7e77e812ab51bd24414665edbaa4707a869708dd.diff
LOG: [Attributor][FIX] Require the store to be aligned for value propagation
Added:
Modified:
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 85b1f0328fc40c..0c2f39974f5a2f 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -1080,8 +1080,16 @@ struct AAPointerInfoImpl
bool AllInSameNoSyncFn = IsAssumedNoSync;
bool InstIsExecutedByInitialThreadOnly =
ExecDomainAA && ExecDomainAA->isExecutedByInitialThreadOnly(I);
+
+ // If the function is not ending in aligned barriers, we need the stores to
+ // be in aligned barriers. The load being in one is not sufficient since the
+ // store might be executed by a thread that disappears after, causing the
+ // aligned barrier guarding the load to unblock and the load to read a value
+ // that has no CFG path to the load.
bool InstIsExecutedInAlignedRegion =
- ExecDomainAA && ExecDomainAA->isExecutedInAlignedRegion(A, I);
+ FindInterferingReads && ExecDomainAA &&
+ ExecDomainAA->isExecutedInAlignedRegion(A, I);
+
if (InstIsExecutedInAlignedRegion || InstIsExecutedByInitialThreadOnly)
A.recordDependence(*ExecDomainAA, QueryingAA, DepClassTy::OPTIONAL);
@@ -1107,7 +1115,8 @@ struct AAPointerInfoImpl
if (!FnExecDomainAA)
return false;
if (InstIsExecutedInAlignedRegion ||
- FnExecDomainAA->isExecutedInAlignedRegion(A, I)) {
+ (FindInterferingWrites &&
+ FnExecDomainAA->isExecutedInAlignedRegion(A, I))) {
A.recordDependence(*FnExecDomainAA, QueryingAA, DepClassTy::OPTIONAL);
return true;
}
diff --git a/llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll b/llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll
index b91cf8e6801eb1..5d630d9e7966a7 100644
--- a/llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll
+++ b/llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll
@@ -78,8 +78,8 @@ define void @kernel() "kernel" {
; TUNIT-NEXT: br label [[IF_MERGE:%.*]]
; TUNIT: if.else:
; TUNIT-NEXT: call void @barrier() #[[ATTR6:[0-9]+]]
-; TUNIT-NEXT: call void @use1(i32 undef) #[[ATTR7:[0-9]+]]
-; TUNIT-NEXT: call void @llvm.assume(i1 undef)
+; TUNIT-NEXT: call void @use1(i32 1) #[[ATTR7:[0-9]+]]
+; TUNIT-NEXT: call void @llvm.assume(i1 true)
; TUNIT-NEXT: call void @barrier() #[[ATTR6]]
; TUNIT-NEXT: br label [[IF_MERGE]]
; TUNIT: if.merge:
@@ -102,8 +102,8 @@ define void @kernel() "kernel" {
; CGSCC-NEXT: br label [[IF_MERGE:%.*]]
; CGSCC: if.else:
; CGSCC-NEXT: call void @barrier() #[[ATTR6:[0-9]+]]
-; CGSCC-NEXT: call void @use1(i32 undef) #[[ATTR6]]
-; CGSCC-NEXT: call void @llvm.assume(i1 undef)
+; CGSCC-NEXT: call void @use1(i32 1) #[[ATTR6]]
+; CGSCC-NEXT: call void @llvm.assume(i1 true)
; CGSCC-NEXT: call void @barrier() #[[ATTR6]]
; CGSCC-NEXT: br label [[IF_MERGE]]
; CGSCC: if.merge:
@@ -492,26 +492,34 @@ S:
ret void
}
-; FIXME: We should not replace the load or delete the second store.
+; We should not replace the load or delete the second store.
define void @kernel4d1(i1 %c) "kernel" {
; TUNIT: Function Attrs: norecurse
; TUNIT-LABEL: define {{[^@]+}}@kernel4d1
; TUNIT-SAME: (i1 [[C:%.*]]) #[[ATTR0]] {
+; TUNIT-NEXT: store i32 0, ptr addrspace(3) @QD1, align 4
; TUNIT-NEXT: br i1 [[C]], label [[S:%.*]], label [[L:%.*]]
; TUNIT: L:
-; TUNIT-NEXT: call void @use1(i32 0) #[[ATTR7]]
+; TUNIT-NEXT: call void @barrier() #[[ATTR7]]
+; TUNIT-NEXT: [[V:%.*]] = load i32, ptr addrspace(3) @QD1, align 4
+; TUNIT-NEXT: call void @use1(i32 [[V]]) #[[ATTR7]]
; TUNIT-NEXT: ret void
; TUNIT: S:
+; TUNIT-NEXT: store i32 2, ptr addrspace(3) @QD1, align 4
; TUNIT-NEXT: ret void
;
; CGSCC: Function Attrs: norecurse
; CGSCC-LABEL: define {{[^@]+}}@kernel4d1
; CGSCC-SAME: (i1 [[C:%.*]]) #[[ATTR0]] {
+; CGSCC-NEXT: store i32 0, ptr addrspace(3) @QD1, align 4
; CGSCC-NEXT: br i1 [[C]], label [[S:%.*]], label [[L:%.*]]
; CGSCC: L:
-; CGSCC-NEXT: call void @use1(i32 0) #[[ATTR6]]
+; CGSCC-NEXT: call void @barrier() #[[ATTR6]]
+; CGSCC-NEXT: [[V:%.*]] = load i32, ptr addrspace(3) @QD1, align 4
+; CGSCC-NEXT: call void @use1(i32 [[V]]) #[[ATTR6]]
; CGSCC-NEXT: ret void
; CGSCC: S:
+; CGSCC-NEXT: store i32 2, ptr addrspace(3) @QD1, align 4
; CGSCC-NEXT: ret void
;
store i32 0, ptr addrspace(3) @QD1
@@ -559,14 +567,14 @@ S:
ret void
}
-; FIXME: We should not replace the load with undef.
+; We should not replace the load with undef.
define void @kernel4d2(i1 %c) "kernel" {
; TUNIT: Function Attrs: norecurse
; TUNIT-LABEL: define {{[^@]+}}@kernel4d2
; TUNIT-SAME: (i1 [[C:%.*]]) #[[ATTR0]] {
; TUNIT-NEXT: br i1 [[C]], label [[S:%.*]], label [[L:%.*]]
; TUNIT: L:
-; TUNIT-NEXT: call void @use1(i32 undef) #[[ATTR7]]
+; TUNIT-NEXT: call void @use1(i32 2) #[[ATTR7]]
; TUNIT-NEXT: ret void
; TUNIT: S:
; TUNIT-NEXT: ret void
@@ -576,7 +584,7 @@ define void @kernel4d2(i1 %c) "kernel" {
; CGSCC-SAME: (i1 [[C:%.*]]) #[[ATTR0]] {
; CGSCC-NEXT: br i1 [[C]], label [[S:%.*]], label [[L:%.*]]
; CGSCC: L:
-; CGSCC-NEXT: call void @use1(i32 undef) #[[ATTR6]]
+; CGSCC-NEXT: call void @use1(i32 2) #[[ATTR6]]
; CGSCC-NEXT: ret void
; CGSCC: S:
; CGSCC-NEXT: ret void
@@ -625,14 +633,14 @@ S:
ret void
}
-; FIXME: We should not replace the load with undef.
+; We should not replace the load with undef.
define void @kernel4d3(i1 %c) "kernel" {
; TUNIT: Function Attrs: norecurse
; TUNIT-LABEL: define {{[^@]+}}@kernel4d3
; TUNIT-SAME: (i1 [[C:%.*]]) #[[ATTR0]] {
; TUNIT-NEXT: br i1 [[C]], label [[S:%.*]], label [[L:%.*]]
; TUNIT: L:
-; TUNIT-NEXT: call void @use1(i32 undef) #[[ATTR7]]
+; TUNIT-NEXT: call void @use1(i32 2) #[[ATTR7]]
; TUNIT-NEXT: ret void
; TUNIT: S:
; TUNIT-NEXT: ret void
@@ -642,7 +650,7 @@ define void @kernel4d3(i1 %c) "kernel" {
; CGSCC-SAME: (i1 [[C:%.*]]) #[[ATTR0]] {
; CGSCC-NEXT: br i1 [[C]], label [[S:%.*]], label [[L:%.*]]
; CGSCC: L:
-; CGSCC-NEXT: call void @use1(i32 undef) #[[ATTR6]]
+; CGSCC-NEXT: call void @use1(i32 2) #[[ATTR6]]
; CGSCC-NEXT: ret void
; CGSCC: S:
; CGSCC-NEXT: ret void
More information about the llvm-commits
mailing list