-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Improve nop-match simplification #68481
Closed
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2cf45bc
Fix SimplifyArmIdentity not working with temporaries and storage markers
sinkuu d0a9500
Add test
sinkuu bde6308
Add SinkCommonCodeFromPredecessors pass
sinkuu 4183719
Dedup predecessors and filter out non-goto blocks
sinkuu 4ff009b
Don't run on types with destructors
sinkuu b2a9b6b
Check statements length
sinkuu f7640ff
Add/fix comment
sinkuu 99a5c54
Fix comment
sinkuu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
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.
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.
Can you elaborate on why we should be doing this optimization in debug mode (and why we shouldn't instead run the storage and temporary elimination)? Will this make
debug
mode compile faster in all cases?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.
Sorry for the late reply!
AFAIK
mir-opt-level
is always1
unless explicitly specified, regardless ofrelease
ordebug
build.mir-opt-level
is independent from optimization level, andcargo
does not set it. (-Zmir-optlevel
is an unstable flag and setting it to2
or larger is prone to ICE/miscompile anyway.)You can confirm this by building MIR of this playground in
release
/debug
build. Temporaries are not eliminated even inrelease
build, andSimplifyArmIdentity
is not working.That said, the purpose of this PR is to improve the codegen of identical
match
inrelase
build.diff
ofcargo rustc --release -- --emit=llvm-ir
, using the same code as the playground above, before/after this PRThere 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.
Regarding the compiler performance: I locally run rustc-perf, and it looks perf-neutral. The 2nd point in #66234 (comment) is still required for these optimizations to be useful in real cases.
Improved SimplifyArmIdentity
Improved SimplifyArmIdentity + SinkCommonCodeFromPredecessors
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.
So there's two things I'm worried about here:
we're slowly adding more optimizations to debug mode, which by it's very definition should be easy to debug with a debugger. Such optimizations can easily end up messing up the source. This one doesn't do it yet, but still.
You essentially had to implement an optimization twice, once for mir-opt-level 1 and once for mir-opt-level 2. I feel like that needlessly complicates our optimizations.
Instead of implementing this optimization twice, how about moving the ICEing optimizations to mir-opt-level 3 and making mir-opt-level 2 the standard for
--release
?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.
I realized this PR is already debuginfo-breaking. If the debugger was stepping on
match
, it would point to whichever arm the optimizer reduced all other arms into.Your plan sounds right. Efforts should be concentrated on fixing/improving advanced MIR optimizations rather than adding ad-hoc optimization passes.
I'll close this PR. Thank you for your time, @oli-obk!