Skip to content

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

Merged
merged 3 commits into from
Jul 13, 2013

Conversation

dotdash
Copy link
Contributor

@dotdash dotdash commented Jul 13, 2013

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.

@dotdash
Copy link
Contributor Author

dotdash commented Jul 13, 2013

This currently results in worse optimized code :-/

@pcwalton
Copy link
Contributor

How much worse? I'm inclined to merge it anyway if it's fine.

@graydon
Copy link
Contributor

graydon commented Jul 13, 2013

Likewise, curious how much worse we're talking. Does it compile any faster on O0?

@dotdash
Copy link
Contributor Author

dotdash commented Jul 13, 2013

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.

dotdash added 3 commits July 13, 2013 13:33
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.
@dotdash
Copy link
Contributor Author

dotdash commented Jul 13, 2013

The new version shows no visible performance regression with -Z time-passes anymore and a cursory scan of a diff of the optimized librustc.ll from before and after the changes revealed only changes of label names. Should be good now.

@dotdash
Copy link
Contributor Author

dotdash commented Jul 13, 2013

Build times for unoptimized libstd build with an unoptimized rustc:

Before

time: 2.736 s   parsing
time: 0.233 s   configuration 1
time: 2.903 s   expansion
time: 0.364 s   configuration 2
time: 0.271 s   maybe building test harness
time: 0.000 s   extra injection
time: 0.254 s   ast indexing
time: 0.054 s   external crate/lib resolution
time: 0.055 s   language item collection
time: 1.146 s   resolution
time: 0.000 s   looking for entry point
time: 0.138 s   freevar finding
time: 0.181 s   region resolution
time: 0.069 s   region parameterization inference
time: 0.486 s   type collecting
time: 0.566 s   coherence checking
time: 7.525 s   type checking
time: 0.225 s   const marking
time: 0.052 s   const checking
time: 0.121 s   privacy checking
time: 0.063 s   effect checking
time: 0.039 s   loop checking
time: 0.412 s   compute moves
time: 0.096 s   match checking
time: 0.338 s   liveness checking
time: 1.395 s   borrow checking
time: 0.184 s   kind checking
time: 0.125 s   reachability checking
time: 0.565 s   lint checking
time: 14.583 s  translation
time: 4.616 s   LLVM passes
time: 0.101 s   linking

After

time: 2.549 s   parsing
time: 0.215 s   configuration 1
time: 2.738 s   expansion
time: 0.340 s   configuration 2
time: 0.252 s   maybe building test harness
time: 0.000 s   extra injection
time: 0.240 s   ast indexing
time: 0.048 s   external crate/lib resolution
time: 0.049 s   language item collection
time: 1.044 s   resolution
time: 0.000 s   looking for entry point
time: 0.121 s   freevar finding
time: 0.168 s   region resolution
time: 0.063 s   region parameterization inference
time: 0.453 s   type collecting
time: 0.530 s   coherence checking
time: 6.901 s   type checking
time: 0.212 s   const marking
time: 0.047 s   const checking
time: 0.110 s   privacy checking
time: 0.057 s   effect checking
time: 0.034 s   loop checking
time: 0.384 s   compute moves
time: 0.088 s   match checking
time: 0.311 s   liveness checking
time: 1.320 s   borrow checking
time: 0.168 s   kind checking
time: 0.117 s   reachability checking
time: 0.505 s   lint checking
time: 13.802 s  translation
time: 4.457 s   LLVM passes
time: 0.096 s   linking

@graydon
Copy link
Contributor

graydon commented Jul 13, 2013

Great!

bors added a commit that referenced this pull request Jul 13, 2013
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.
@bors bors closed this Jul 13, 2013
@bors bors merged commit 1d2e1a9 into rust-lang:master Jul 13, 2013
@dotdash dotdash deleted the empty_blocks branch July 13, 2013 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants