-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Fix SimplifyArmIdentity
MIR opt
#94177
Conversation
This comment has been minimized.
This comment has been minimized.
Sigh, this will have to wait until tomorrow |
d406e0e
to
85ebacc
Compare
Was missing a single |
This comment has been minimized.
This comment has been minimized.
85ebacc
to
6070f63
Compare
Oop, didn't know there was a codegen test. I've modified it for now by turning on LLVM optimizations. With |
/// bound. | ||
/// 2. For each bundle, if any assignment to a temporary is via `copy`, then this is sufficient to | ||
/// prove that the field is `Copy`. In this case, we keep all assignments to temporaries | ||
/// associated with this bundle. The move mode of the assignment out of `src` is forced to be |
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.
SimplifyLocals
should be able to remove stray assignments. Should this pass end by a call to simplify_locals
when it has left Copy
assignments behind?
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.
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.
Could you demonstrate what mir-opt tests look like with both optimizations running?
Other option: we are creating a list of StorageDead
statements to be moved. Can it be used to kill off unused Copy
locals?
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.
Actually, I just had a different idea. If that doesn't pan out though, I'll add a test demonstrating this
This comment has been minimized.
This comment has been minimized.
Hm, that test doesn't seem to run locally by default. Is there anyway to get |
You need to specify another |
☔ The latest upstream changes (presumably #94209) made this pull request unmergeable. Please resolve the merge conflicts. |
This fixes a number of soundness issues that existed in the pass previously, and additionally makes it more flexible.
6070f63
to
e59021d
Compare
@cjgillot I've added a call to |
Thanks. |
My hope is that I can also start working on dest prop and fix that so that it can run immediately after. At that point, I can remove the |
This commit makes a couple of changes: 1. Rename `simplify-arm` to `simplify_arm` so that it appears with the output files. 2. Deduplicate tests across `simplify_arm` and `simplify_try`. This moves all the tests to `simplify_arm`, where output for both opts is emitted where appropriate. Output for `SimplifyLocals` and `DestProp` is removed, because `DestProp` is unsound and not interesting for this case anyway, while `simplify_arm` calls `simplify_locals` internally anyway 3. Blesses the `simplify_arm` tests with the new optimization. squash 1
This adds a couple more tests checking code that should be optimized, and even more checking code that shouldn't be.
e59021d
to
dc3bc90
Compare
I've added the tests back in. Would be interested in seeing the results of a perf run of this, I don't expect it to be too expensive, but I have no idea how often it will fire. |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit dc3bc90 with merge 925b41079b7b144f270a6fd5883c7db9d5864965... |
☀️ Try build successful - checks-actions |
Queued 925b41079b7b144f270a6fd5883c7db9d5864965 with parent c651ba8, future comparison URL. |
I found a comment in other code indicating that self-assignment is UB. I can push an update to this pass that avoids emitting such a self-assignment, but is that the case? If so, why? |
Finished benchmarking commit (925b41079b7b144f270a6fd5883c7db9d5864965): comparison url. Summary: This benchmark run shows 2 relevant improvements 🎉 but 1 relevant regression 😿 to instruction counts.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never |
I've converted this to a draft to keep it from being merged, pending #94590 . That will require some adjustments to this pass. Also there are (at least) two additional checks that need to be introduced for this to be correct: The type needs to be an ADT, not a generator, and the move into self needs to be avoided. In principle though, not a huge amount will change and this should still be ready for an initial review |
I have a version of this that I think is ready to review, it's only blocked on #96090 . Once that lands, I'll push updates |
@JakobDegen FYI: It looks like #96090 has landed at this point. |
Yeah, I'm still waiting for more changes though. I can close this if it's better to not have it up |
I'm closing this PR because it is still unsound in some very hard to fix ways. |
Delete `SimplifyArmIdentity` and `SimplifyBranchSame` mir opts I had attempted to fix the first of these opts in rust-lang#94177 . However, despite that PR already being a full re-write, it still did not fix some of the core soundness issues. The optimizations that are attempted here are likely to be desirable, but I do not expect any of the currently written code to survive into a sound implementation. Deleting the code keeps us from having to maintain the passes in the meantime. Closes rust-lang#77359 , closes rust-lang#72800 , closes rust-lang#78628 r? `@cjgillot`
Delete `SimplifyArmIdentity` and `SimplifyBranchSame` mir opts I had attempted to fix the first of these opts in rust-lang#94177 . However, despite that PR already being a full re-write, it still did not fix some of the core soundness issues. The optimizations that are attempted here are likely to be desirable, but I do not expect any of the currently written code to survive into a sound implementation. Deleting the code keeps us from having to maintain the passes in the meantime. Closes rust-lang#77359 , closes rust-lang#72800 , closes rust-lang#78628 r? ``@cjgillot``
Delete `SimplifyArmIdentity` and `SimplifyBranchSame` mir opts I had attempted to fix the first of these opts in rust-lang#94177 . However, despite that PR already being a full re-write, it still did not fix some of the core soundness issues. The optimizations that are attempted here are likely to be desirable, but I do not expect any of the currently written code to survive into a sound implementation. Deleting the code keeps us from having to maintain the passes in the meantime. Closes rust-lang#77359 , closes rust-lang#72800 , closes rust-lang#78628 r? ```@cjgillot```
Closes #77359
Closes #72800
Closes #78628
This is a near full re-write of the pass. The StorageLive issue would have been relatively easy to fix, but the use after move issue was more complicated. The new version of the pass documents very explicitly how
copy
/move
things are handled, and takes care to uphold that. This version also increases the flexibility of the pass. We allow any number of fields (instead of just one) and also allow moving into ourselves.This pass does a little less than the original version. In particular, it leaves all the storage and some of the temporary assignments in. I do think that it is in general the right idea to not try and also remove those here. I've written #94118 which is supposed to run soon after this and is designed to remove these kinds of things. Unfortunately, this also means that a lot of the tests around
SimplifyBranchSame
break, because that optimization no longer runs. I've gone and deleted these tests for now. I don't know if we even want to keep theSimplifyBranchSame
pass at all though; this pass is enough to get LLVM to output the right thing, so it might be enough to let the remaining issues get swept up in DSE + SimplifyCFG or something like that.The diff is pretty big, but that's mostly tests. I've organized the commits so that hopefully the changes to the test suite are pretty easy to follow.
cc @wesleywiser who seems to have been the last person to touch this
r? rust-lang/mir-opt