-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Inliner] Don't propagate access attr to byval params #112256
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
goldsteinn
merged 3 commits into
llvm:main
from
goldsteinn:goldsteinn/byval-inline-attr
Oct 15, 2024
Merged
[Inliner] Don't propagate access attr to byval params #112256
goldsteinn
merged 3 commits into
llvm:main
from
goldsteinn:goldsteinn/byval-inline-attr
Oct 15, 2024
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
@llvm/pr-subscribers-llvm-transforms Author: None (goldsteinn) Changes
Full diff: https://github.com/llvm/llvm-project/pull/112256.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 110fd6de5c6968..c8a2fd95e3a970 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1398,7 +1398,7 @@ static void AddParamAndFnBasicAttributes(const CallBase &CB,
if (!Arg)
continue;
- if (AL.hasParamAttr(I, Attribute::ByVal))
+ if (NewInnerCB->getParamAttr(I, Attribute::ByVal).isValid())
// It's unsound to propagate memory attributes to byval arguments.
// Even if CalledFunction doesn't e.g. write to the argument,
// the call to NewInnerCB may write to its by-value copy.
@@ -1407,24 +1407,29 @@ static void AddParamAndFnBasicAttributes(const CallBase &CB,
unsigned ArgNo = Arg->getArgNo();
// If so, propagate its access attributes.
AL = AL.addParamAttributes(Context, I, ValidParamAttrs[ArgNo]);
+ auto NewCBHasParamAttr = [&](Attribute::AttrKind Kind) {
+ return AL.hasParamAttr(I, Kind) ||
+ NewInnerCB->getParamAttr(I, Kind).isValid();
+ };
+
// We can have conflicting attributes from the inner callsite and
// to-be-inlined callsite. In that case, choose the most
// restrictive.
// readonly + writeonly means we can never deref so make readnone.
- if (AL.hasParamAttr(I, Attribute::ReadOnly) &&
- AL.hasParamAttr(I, Attribute::WriteOnly))
+ if (NewCBHasParamAttr(Attribute::ReadOnly) &&
+ NewCBHasParamAttr(Attribute::WriteOnly))
AL = AL.addParamAttribute(Context, I, Attribute::ReadNone);
// If have readnone, need to clear readonly/writeonly
- if (AL.hasParamAttr(I, Attribute::ReadNone)) {
+ if (NewCBHasParamAttr(Attribute::ReadNone)) {
AL = AL.removeParamAttribute(Context, I, Attribute::ReadOnly);
AL = AL.removeParamAttribute(Context, I, Attribute::WriteOnly);
}
// Writable cannot exist in conjunction w/ readonly/readnone
- if (AL.hasParamAttr(I, Attribute::ReadOnly) ||
- AL.hasParamAttr(I, Attribute::ReadNone))
+ if (NewCBHasParamAttr(Attribute::ReadOnly) ||
+ NewCBHasParamAttr(Attribute::ReadNone))
AL = AL.removeParamAttribute(Context, I, Attribute::Writable);
}
NewInnerCB->setAttributes(AL);
diff --git a/llvm/test/Transforms/Inline/access-attributes-prop.ll b/llvm/test/Transforms/Inline/access-attributes-prop.ll
index 2c55f5f3b1f6ca..5051c92345ec75 100644
--- a/llvm/test/Transforms/Inline/access-attributes-prop.ll
+++ b/llvm/test/Transforms/Inline/access-attributes-prop.ll
@@ -580,3 +580,23 @@ define ptr @callee_bad_param_prop(ptr readonly %x) {
%r = tail call ptr @llvm.ptrmask(ptr %x, i64 -1)
ret ptr %r
}
+
+define dso_local void @foo_byval_readonly2(ptr readonly %p) {
+; CHECK-LABEL: define {{[^@]+}}@foo_byval_readonly2
+; CHECK-SAME: (ptr readonly [[P:%.*]]) {
+; CHECK-NEXT: call void @bar4(ptr [[P]])
+; CHECK-NEXT: ret void
+;
+ call void @bar4(ptr %p)
+ ret void
+}
+
+define void @prop_byval_readonly2(ptr %p) {
+; CHECK-LABEL: define {{[^@]+}}@prop_byval_readonly2
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT: call void @bar4(ptr [[P]])
+; CHECK-NEXT: ret void
+;
+ call void @foo_byval_readonly2(ptr %p)
+ ret void
+}
|
We previously only handled the case where the `byval` attr was in the callbase's param attr list. This PR also handles the case if the `ByVal` was a param attr on the function's param attr list.
ae11d1f
to
74f7931
Compare
andjo403
reviewed
Oct 14, 2024
nikic
approved these changes
Oct 14, 2024
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.
LGTM
/cherry-pick 3c777f0 |
llvmbot
pushed a commit
to llvmbot/llvm-project
that referenced
this pull request
Oct 15, 2024
- **[Inliner] Add tests for bad propagationg of access attr for `byval` param; NFC** - **[Inliner] Don't propagate access attr to `byval` params** We previously only handled the case where the `byval` attr was in the callbase's param attr list. This PR also handles the case if the `ByVal` was a param attr on the function's param attr list. (cherry picked from commit 3c777f0)
/pull-request #112365 |
DanielCChen
pushed a commit
to DanielCChen/llvm-project
that referenced
this pull request
Oct 16, 2024
- **[Inliner] Add tests for bad propagationg of access attr for `byval` param; NFC** - **[Inliner] Don't propagate access attr to `byval` params** We previously only handled the case where the `byval` attr was in the callbase's param attr list. This PR also handles the case if the `ByVal` was a param attr on the function's param attr list.
tru
pushed a commit
to llvmbot/llvm-project
that referenced
this pull request
Oct 29, 2024
- **[Inliner] Add tests for bad propagationg of access attr for `byval` param; NFC** - **[Inliner] Don't propagate access attr to `byval` params** We previously only handled the case where the `byval` attr was in the callbase's param attr list. This PR also handles the case if the `ByVal` was a param attr on the function's param attr list. (cherry picked from commit 3c777f0)
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.
byval
param; NFCbyval
paramsWe previously only handled the case where the
byval
attr was in thecallbase's param attr list. This PR also handles the case if the
ByVal
was a param attr on the function's param attr list.