-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[IRGen] Mark inout ptrs noalias. #42503
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
Conversation
dd502b3
to
9469330
Compare
@swift-ci please test |
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
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.
This should be applied to all indirect arguments except @inout_aliasable
.
What's the purpose of doing this for "pointer types" only? What LLVM alias analysis issues need to be avoided, how does this check avoid them, and when can we stop hiding info from LLVM?
lib/IRGen/GenCall.cpp
Outdated
// Thanks to exclusivity checking, it is not possible to alias inouts. | ||
if (paramSILType.getASTType()->getAnyPointerElementType()) { | ||
// To ward against issues with LLVM's alias analysis, for now, only add the | ||
// attribute if it's a pointer being passed inout. | ||
b.addAttribute(llvm::Attribute::NoAlias); | ||
} | ||
// Aliasing inouts can't be captured without doing unsafe stuff. |
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.
Indirect_InoutAliasable
arguments do alias. So I think the code should check aliasable
.
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.
Thanks! Fixed.
Thanks to exclusivity checking, inout arguments can be marked noalias. In the fullness of time, this should be applied in general. As an incremental step towards marking all such arguments noalias, start by marking inout arguments of pointer type noalias. Take this conservative step rather than always applying the attribute to ward against issues with LLVM's alias analysis. rdar://76540030
9469330
to
d70d391
Compare
Deferring to @aschwaighofer to answer the questions about staging this in like this and starting with pointer types. |
@swift-ci please test |
There are reoccuring bugs in LLVM's alias analysis (as it is continuously "improved"). They cause hard to debug memory bugs and would impose a cost on those who have to debug them. This cost can be weight against (performance) benefits that we suspect to be getting. My suggestion was to introduce the use of At some later point we can remove the constraint and see where we end up with then. |
... |
When we have rewritten the code generation backend in Swift. |
Thanks to exclusivity checking, inout arguments can be marked noalias.
In the fullness of time, this should be applied in general.
As an incremental step towards marking all such arguments noalias, start
by marking inout arguments of pointer type noalias. Take this
conservative step rather than always applying the attribute to ward
against issues with LLVM's alias analysis.
rdar://76540030