-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Attributor] Don't replace addrspacecast (ptr null to ptr addrspace(x)) with ptr addrspace(x) null
#126779
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
[Attributor] Don't replace addrspacecast (ptr null to ptr addrspace(x)) with ptr addrspace(x) null
#126779
Conversation
|
@llvm/pr-subscribers-backend-amdgpu @llvm/pr-subscribers-llvm-transforms Author: Shilei Tian (shiltian) Changes
Fixes #115083. Full diff: https://github.com/llvm/llvm-project/pull/126779.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 17e7fada1082762..143215ec91706b3 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -10970,6 +10970,15 @@ struct AAPotentialValuesImpl : AAPotentialValues {
Value *NewV = getSingleValue(A, *this, getIRPosition(), Values);
if (!NewV || NewV == &OldV)
continue;
+ // FIXME: ConstantPointerNull represents a pointer with value 0, but it
+ // doesn’t necessarily mean a nullptr. `ptr addrspace(x) null` is not the
+ // same as `addrspacecast (ptr null to ptr addrspace(x))` if the nullptr
+ // in AS x is not zero. Therefore, we can't simply replace it.
+ if (isa<ConstantPointerNull>(NewV) && isa<ConstantExpr>(OldV)) {
+ auto &CE = cast<ConstantExpr>(OldV);
+ if (CE.getOpcode() == Instruction::AddrSpaceCast)
+ continue;
+ }
if (getCtxI() &&
!AA::isValidAtPosition({*NewV, *getCtxI()}, A.getInfoCache()))
continue;
diff --git a/llvm/test/Transforms/Attributor/do-not-replace-addrspacecast-with-constantpointernull.ll b/llvm/test/Transforms/Attributor/do-not-replace-addrspacecast-with-constantpointernull.ll
new file mode 100644
index 000000000000000..77eb5fed81d3cfa
--- /dev/null
+++ b/llvm/test/Transforms/Attributor/do-not-replace-addrspacecast-with-constantpointernull.ll
@@ -0,0 +1,39 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S -passes=attributor $s -o - | FileCheck %s
+
+define i32 @bar(ptr %p0, ptr addrspace(5) %p5) {
+; CHECK-LABEL: define i32 @bar(
+; CHECK-SAME: ptr nofree readonly captures(none) [[P0:%.*]], ptr addrspace(5) nofree readonly [[P5:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[TMP0:%.*]] = icmp eq ptr addrspace(5) [[P5]], addrspacecast (ptr null to ptr addrspace(5))
+; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[TMP0]], ptr [[P0]], ptr null
+; CHECK-NEXT: switch i8 0, label %[[BB_2:.*]] [
+; CHECK-NEXT: i8 0, label %[[BB_0:.*]]
+; CHECK-NEXT: i8 1, label %[[BB_1:.*]]
+; CHECK-NEXT: ]
+; CHECK: [[BB_0]]:
+; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[TMP1]], align 4
+; CHECK-NEXT: ret i32 [[TMP2]]
+; CHECK: [[BB_1]]:
+; CHECK-NEXT: unreachable
+; CHECK: [[BB_2]]:
+; CHECK-NEXT: unreachable
+;
+entry:
+ %0 = icmp eq ptr addrspace(5) %p5, addrspacecast (ptr null to ptr addrspace(5))
+ %1 = select i1 %0, ptr %p0, ptr null
+ switch i8 0, label %bb.2 [
+ i8 0, label %bb.0
+ i8 1, label %bb.1
+ ]
+
+bb.0: ; preds = %entry
+ %2 = load i32, ptr %1, align 4
+ ret i32 %2
+
+bb.1: ; preds = %entry
+ ret i32 0
+
+bb.2: ; preds = %entry
+ ret i32 1
+}
|
llvm/test/Transforms/Attributor/do-not-replace-addrspacecast-with-constantpointernull.ll
Outdated
Show resolved
Hide resolved
llvm/test/Transforms/Attributor/do-not-replace-addrspacecast-with-constantpointernull.ll
Outdated
Show resolved
Hide resolved
6ae31b3 to
23d8876
Compare
This stack of pull requests is managed by Graphite. Learn more about stacking. |
dcd5a83 to
93c20b2
Compare
|
Ping. AFAICT, only |
llvm/test/Transforms/Attributor/do-not-replace-addrspacecast-with-constantpointernull.ll
Outdated
Show resolved
Hide resolved
|
This will be properly resolved after #131557 (as well as its follow-up patches). |
AddrSpaceCast with ConstantPointerNulladdrspacecast (ptr null to ptr addrspace(x)) with ptr addrspace(x) null
93c20b2 to
48eff91
Compare
48eff91 to
fe5e442
Compare
|
I figured it's gonna take much longer time to change the semantics of |
llvm/test/Transforms/Attributor/do-not-replace-addrspacecast-with-constantpointernull.ll
Outdated
Show resolved
Hide resolved
llvm/test/Transforms/Attributor/do-not-replace-addrspacecast-with-constantpointernull.ll
Outdated
Show resolved
Hide resolved
e7c3060 to
48ae8cd
Compare
48ae8cd to
ec76d44
Compare
jdoerfert
left a comment
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'm not super convinced but it seems necessary for now.
LG
ec76d44 to
2bbd606
Compare
`ConstantPointerNull` represents a pointer with value 0, but it doesn’t necessarily mean a nullptr. `ptr addrspace(x) null` is not the same as `addrspacecast (ptr null to ptr addrspace(x))` if the nullptr in AS x is not zero. Therefore, we can't simply replace it. Fixes #115083.
2bbd606 to
7be9429
Compare

ConstantPointerNullrepresents a pointer with value 0, but it doesn’tnecessarily mean a
nullptr.ptr addrspace(x) nullis not the same asaddrspacecast (ptr null to ptr addrspace(x))if thenullptrin AS X is notzero. Therefore, we can't simply replace it.
Fixes #115083.