-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Avoid unnecessary basic blocks for allocas, return and else #7763
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
This currently results in worse optimized code :-/ |
How much worse? I'm inclined to merge it anyway if it's fine. |
Likewise, curious how much worse we're talking. Does it compile any faster on O0? |
Up to about 7% slower in some cases. Looks like it's due to the fact that the final function block doesn't reuse the "return" cleanup path anymore. Trying to fix that now. |
Currently, we always create a dedicated "return" basic block, but when there's only a single predecessor for that block, it can be merged with that predecessor. We can achieve that merge by only creating the return block on demand, avoiding its creation when its not required. Reduces the pre-optimization size of librustc.ll created with --passes "" by about 90k lines which equals about 4%.
When there are no allocas, we don't need a block for them.
If an "if" expression has no "else", we don't have to create an LLVM basic block either.
The new version shows no visible performance regression with |
Build times for unoptimized libstd build with an unoptimized rustc: Before
After
|
Great! |
These commits remove a bunch of empty or otherwise unnecessary blocks, reducing the size of the pre-optimization IR and improving its readability. `librustc.ll` created with `--passes ""` shrinks by about 120k lines which equals about 5% of the total size.
These commits remove a bunch of empty or otherwise unnecessary blocks, reducing the size of the pre-optimization IR and improving its readability.
librustc.ll
created with--passes ""
shrinks by about 120k lines which equals about 5% of the total size.