-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
[InstCombine][FuncAttrs] InstCombine breaks initializes
attribute
#133059
Comments
It is impractical. We should make sure that InstCombine performs a valid refinement. |
Reduced: https://alive2.llvm.org/ce/z/ahKwC-
Instcombine removes the memcpy. I don't see what's wrong with this. It's ok for instcombine to remove the memcpy since anything is at least as defined as poison. The caller cannot assume that contents of the memory are anything other than poison after |
@aeubanks The InstCombine transform is (intended to be) valid, the problem here is just with the spec wording for the initializes attribute.
No. "Initializing" with uninitialized memory is fine for the purposes of this attribute. The elegant way to specify the semantics operationally would be analogous to how we specify writable: Unfortunately, it's not as simple as this, because we can't just say the undef write happens at the entry of the function. initializes only wants to guarantee that "initialization" happens at some point on the path to a normal return. It may be omitted on paths that unwind or diverge. So I think the way to reconcile this would be to essentially keep the current spec, but add that any byte range that is part of initializes but has not been written at the point of return is written with undef then. |
See also #133038 for a related issue. If I take these two together, a way to address both would be:
|
I am fine with this solution. |
Specify the initializes attribute in terms of an "initialized" shadow state, such that: * Loads prior to initialization return undef. * Bytes that are not explicitly initialized are written with undef on function return. This is intended to preserve the core semantics of the attribute, but adjusts the wording in a way that is compatible with existing optimizations, such as insertion of spurious loads and removal of uninitialized writes. Fixes llvm#133038. Fixes llvm#133059.
Specify the initializes attribute in terms of an "initialized" shadow state, such that: * Loads prior to initialization return poison. * Bytes that are not explicitly initialized are written with undef on function return. This is intended to preserve the core semantics of the attribute, but adjusts the wording in a way that is compatible with existing optimizations, such as insertion of spurious loads and removal of uninitialized writes. Fixes llvm/llvm-project#133038. Fixes llvm/llvm-project#133059.
Reproducer: https://alive2.llvm.org/ce/z/rx6rJk
After InstCombine, the last memcpy is dropped as the source buffer is uninitialized (filled with undef (in llvm)/poison (in alive2)).
Should we adjust
initializes
to only account for writing with well-defined values?Generated with rustlantis + llubi.
Original rust mir program: https://gist.github.com/dtcxzyw/78250ce921833ea20c5cb040d29f1a3f
cc @haopliu @nikic
The text was updated successfully, but these errors were encountered: