-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[SimplifyCFG] Switch to use paramHasNonNullAttr
#125383
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
Open
dtcxzyw
wants to merge
1
commit into
llvm:main
Choose a base branch
from
dtcxzyw:perf/simplifycfg-param-nonnull
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nikic
reviewed
Feb 2, 2025
dtcxzyw
added a commit
that referenced
this pull request
Feb 3, 2025
…n `Use` (#125519) Address comment #125383 (comment)
github-actions bot
pushed a commit
to arm/arm-toolchain
that referenced
this pull request
Feb 3, 2025
…` to work on `Use` (#125519) Address comment llvm/llvm-project#125383 (comment)
Icohedron
pushed a commit
to Icohedron/llvm-project
that referenced
this pull request
Feb 11, 2025
…n `Use` (llvm#125519) Address comment llvm#125383 (comment)
nikic
reviewed
Mar 1, 2025
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.
Needs a rebase?
7e90465
to
8cdfdae
Compare
8cdfdae
to
244bf1f
Compare
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-llvm-ir Author: Yingwei Zheng (dtcxzyw) ChangesFull diff: https://github.com/llvm/llvm-project/pull/125383.diff 3 Files Affected:
diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index 8e47e3c7b3a7c..61070aa79b15d 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -1839,7 +1839,11 @@ class CallBase : public Instruction {
/// Extract the number of dereferenceable bytes for a call or
/// parameter (0=unknown).
uint64_t getParamDereferenceableBytes(unsigned i) const {
- return Attrs.getParamDereferenceableBytes(i);
+ uint64_t Bytes = Attrs.getParamDereferenceableBytes(i);
+ if (const Function *F = getCalledFunction())
+ Bytes =
+ std::max(Bytes, F->getAttributes().getParamDereferenceableBytes(i));
+ return Bytes;
}
/// Extract the number of dereferenceable_or_null bytes for a call
@@ -1857,7 +1861,11 @@ class CallBase : public Instruction {
/// Extract the number of dereferenceable_or_null bytes for a
/// parameter (0=unknown).
uint64_t getParamDereferenceableOrNullBytes(unsigned i) const {
- return Attrs.getParamDereferenceableOrNullBytes(i);
+ uint64_t Bytes = Attrs.getParamDereferenceableOrNullBytes(i);
+ if (const Function *F = getCalledFunction())
+ Bytes = std::max(
+ Bytes, F->getAttributes().getParamDereferenceableOrNullBytes(i));
+ return Bytes;
}
/// Extract a test mask for disallowed floating-point value classes for the
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 7f53aa7d4f73d..ea171010c7507 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -8214,8 +8214,8 @@ static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I, bool PtrValu
if (CB->isArgOperand(&Use)) {
unsigned ArgIdx = CB->getArgOperandNo(&Use);
// Passing null to a nonnnull+noundef argument is undefined.
- if (C->isNullValue() && CB->isPassingUndefUB(ArgIdx) &&
- CB->paramHasAttr(ArgIdx, Attribute::NonNull))
+ if (isa<ConstantPointerNull>(C) &&
+ CB->paramHasNonNullAttr(ArgIdx, /*AllowUndefOrPoison=*/false))
return !PtrValueMayBeModified;
// Passing undef to a noundef argument is undefined.
if (isa<UndefValue>(C) && CB->isPassingUndefUB(ArgIdx))
diff --git a/llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll b/llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll
index aae1ab032f36e..2da5d18b63f49 100644
--- a/llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll
+++ b/llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll
@@ -238,7 +238,7 @@ else:
}
declare ptr @fn_nonnull_noundef_arg(ptr nonnull noundef %p)
-declare ptr @fn_nonnull_deref_arg(ptr nonnull dereferenceable(4) %p)
+declare ptr @fn_deref_arg(ptr dereferenceable(4) %p)
declare ptr @fn_nonnull_deref_or_null_arg(ptr nonnull dereferenceable_or_null(4) %p)
declare ptr @fn_nonnull_arg(ptr nonnull %p)
declare ptr @fn_noundef_arg(ptr noundef %p)
@@ -271,7 +271,7 @@ define void @test9_deref(i1 %X, ptr %Y) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[X:%.*]], true
; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
-; CHECK-NEXT: [[TMP1:%.*]] = call ptr @fn_nonnull_deref_arg(ptr [[Y:%.*]])
+; CHECK-NEXT: [[TMP1:%.*]] = call ptr @fn_deref_arg(ptr [[Y:%.*]])
; CHECK-NEXT: ret void
;
entry:
@@ -282,7 +282,7 @@ if:
else:
%phi = phi ptr [ %Y, %entry ], [ null, %if ]
- call ptr @fn_nonnull_deref_arg(ptr %phi)
+ call ptr @fn_deref_arg(ptr %phi)
ret void
}
@@ -290,9 +290,8 @@ else:
define void @test9_deref_or_null(i1 %X, ptr %Y) {
; CHECK-LABEL: @test9_deref_or_null(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[X:%.*]], true
-; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
-; CHECK-NEXT: [[TMP1:%.*]] = call ptr @fn_nonnull_deref_or_null_arg(ptr [[Y:%.*]])
+; CHECK-NEXT: [[Y:%.*]] = select i1 [[X:%.*]], ptr null, ptr [[Y1:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = call ptr @fn_nonnull_deref_or_null_arg(ptr [[Y]])
; CHECK-NEXT: ret void
;
entry:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.