Skip to content

Avoid unnecessary basic blocks for allocas, return and else - #7763

Merged
bors merged 3 commits into
rust-lang:masterfrom
dotdash:empty_blocks
Jul 13, 2013
Merged

Avoid unnecessary basic blocks for allocas, return and else#7763
bors merged 3 commits into
rust-lang:masterfrom
dotdash:empty_blocks

Conversation

@dotdash

Copy link
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

This currently results in worse optimized code :-/

@pcwalton

Copy link
Copy Markdown
Contributor

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

@graydon

Copy link
Copy Markdown
Contributor

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

@dotdash

Copy link
Copy Markdown
ContributorAuthor

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.
@dotdash

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
Contributor

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.
@borsbors closed this Jul 13, 2013
@bors
bors merged commit 1d2e1a9 into rust-lang:masterJul 13, 2013
@dotdash
dotdash deleted the empty_blocks branch July 13, 2013 23:30
U007D pushed a commit to U007D/rust-mos that referenced this pull request Aug 21, 2026
8947: Correctly resolve crate name in use paths when import shadows it r=Veykril a=Veykril
Fixesrust-lang#7763
bors r+
Co-authored-by: Lukas Tobias Wirth <lukastw97@gmail.com>
Sign up for freeto 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

@dotdash@pcwalton@graydon@bors