Uh oh!
There was an error while loading. Please reload this page.
Eliminate excessive null-checks from slice iterators - #21886
Conversation
rust-highfive
commented
Feb 3, 2015
(rust_highfive has picked a reviewer for you, use r? to override) |
huonw
commented
Feb 3, 2015
From the description I take it this doesn't suffer from the compile time problem mentioned in #21418 (comment)? (Out of interest what changed in LLVM? Just general optimisations?) Also, I found that the compiler aborted compiling libcore (can't remember if it was stage1 or stage2) when I did a similar change (#21448); this doesn't suffer from that? |
dotdash
commented
Feb 3, 2015
Right, I compared compile times for (IIRC) rustc_trans and rustc_typeck and there was no measureable difference in compile times with the assume in stage 2 (or maybe it was stage 1 that I tested, shouldn't matter). I also just bootstrapped a new version of #21418 and that took ~24 minutes from finishing stage0 libcore to finishing stage2 librustc. Considering that just rustc_trans took 13 minutes when the slowdown was there, it looks good to me ;-)
I don't know.
The benchmark was taken with the stage2 rustc, so no, it didn't abort. |
huonw
commented
Feb 3, 2015
Could you add the assume to |
dotdash
commented
Feb 3, 2015
Why I originally had it in |
huonw
commented
Feb 3, 2015
Oh, huh. I totally misread this PR. I was thinking this was in |
huonw
commented
Feb 3, 2015
I suspect that means that this doesn't solve a case like http://is.gd/pteFUM, .LBB0_2: testq %rdx, %rdxje .LBB0_4 addl (%rdx), %eax addq$4, %rdx addq $-4, %rcxjne .LBB0_2since there's no |
dotdash
commented
Feb 3, 2015
Will try to see if that helps |
There was a problem hiding this comment.
ptr::null_mut() here and all other uses of 0 as *mut T
There was a problem hiding this comment.
Actually, using is_null() works now, that didn't work the first time I tried, either because of an error on my side or because of the ptrtoint instruction it was generated with the old is_null() implementation.
Thanks!
dotdash
commented
Feb 3, 2015
At least in this case, the |
huonw
commented
Feb 3, 2015
@bors r+ e49f |
alexcrichton
commented
Feb 3, 2015
@bors: rollup |
alexcrichton
commented
Feb 4, 2015
@bors: rollup- |
bors
commented
Feb 4, 2015
⌛ Testing commit e49f6d6 with merge cd0d956... |
bors
commented
Feb 4, 2015
💔 Test failed - auto-win-32-nopt-t |
bluss
commented
Feb 5, 2015
@huonw, that fold testcase seems to have been resolved now, it vectorizes! ( |
huonw
commented
Feb 7, 2015
The failure seems legitimate; although, possibly a LLVM bug? |
dotdash
commented
Feb 9, 2015
Yeah, I can reproduce that in my Windows VM. |
dotdash
commented
Feb 10, 2015
Yup, LLVM bug: http://reviews.llvm.org/D7533 |
Casting the pointer to an integer requires a ptrtoint, while casting 0 to a pointer is directly folded to a `null` value.
The data pointer used in the slice is never null, using assume() to tell LLVM about it gets rid of various unneeded null checks when iterating over the slice. Since the snapshot compiler is still using an older LLVM version, omit the call in stage0, because compile times explode otherwise. Benchmarks from rust-lang#18193 ```` running 5 tests test _range ... bench: 33329 ns/iter (+/- 417) test assembly ... bench: 33299 ns/iter (+/- 58) test enumerate ... bench: 33318 ns/iter (+/- 83) test iter ... bench: 33311 ns/iter (+/- 130) test position ... bench: 33300 ns/iter (+/- 47) test result: ok. 0 passed; 0 failed; 0 ignored; 5 measured ```` Fixesrust-lang#18193
e49f6d6 to
7412d1bComparedotdash
commented
Feb 18, 2015
bors
commented
Feb 18, 2015
⌛ Testing commit 7412d1b with merge c103604... |
bors
commented
Feb 18, 2015
💔 Test failed - auto-win-32-nopt-t |
alexcrichton
commented
Feb 18, 2015
@bors: retry |
bors
commented
Feb 18, 2015
The data pointer used in the slice is never null, using assume() to tell LLVM about it gets rid of various unneeded null checks when iterating over the slice. Since the snapshot compiler is still using an older LLVM version, omit the call in stage0, because compile times explode otherwise. Benchmarks from #18193 ```` running 5 tests test _range ... bench: 33329 ns/iter (+/- 417) test assembly ... bench: 33299 ns/iter (+/- 58) test enumerate ... bench: 33318 ns/iter (+/- 83) test iter ... bench: 33311 ns/iter (+/- 130) test position ... bench: 33300 ns/iter (+/- 47) test result: ok. 0 passed; 0 failed; 0 ignored; 5 measured ```` Fixes#18193
bors
commented
Feb 18, 2015
💔 Test failed - auto-win-32-nopt-t |
aturon
commented
Feb 18, 2015
@bors: retry |
The data pointer used in the slice is never null, using assume() to tell LLVM about it gets rid of various unneeded null checks when iterating over the slice. Since the snapshot compiler is still using an older LLVM version, omit the call in stage0, because compile times explode otherwise. Benchmarks from rust-lang#18193 ```` running 5 tests test _range ... bench: 33329 ns/iter (+/- 417) test assembly ... bench: 33299 ns/iter (+/- 58) test enumerate ... bench: 33318 ns/iter (+/- 83) test iter ... bench: 33311 ns/iter (+/- 130) test position ... bench: 33300 ns/iter (+/- 47) test result: ok. 0 passed; 0 failed; 0 ignored; 5 measured ```` Fixesrust-lang#18193
This adds the assume() calls back that got lost when rebasing rust-lang#21886.
This adds the assume() calls back that got lost when rebasing #21886.
frol
commented
May 9, 2018
Could someone, please, point me to a tracking issue or a documentation about the excessive null-checks? I want to learn more about the cause of extra pubfnfoo(s:&[u32]) -> u32{
s.iter().sum()}pubfnfoo(s:&[u32]) -> u32{
s.iter().sum()}pubfnfoo(s:Vec<i32>) -> usize{
s.len()}and even pubfnfoo(_s:Vec<i32>) -> usize{0}produces assembly code which might have been avoided: playground::foo:movq8(%rdi), %rsi testq %rsi, %rsije .LBB0_2 pushq %raxmovq (%rdi), %rdi shlq$2, %rsi movl$4, %edx callq __rust_dealloc@PLT addq$8, %rsp.LBB0_2: xorl %eax, %eax retq |
nagisa
commented
May 9, 2018
In both these cases the length, rather than pointer is being checked. For the |
frol
commented
May 9, 2018
Indeed, I completely forgot that the owned object must be deallocated here.
Right... @nagisa I am sorry for the trouble! Rust is awesome! :) |
…-gen-trait-fn-body Replace make constructor with syntaxFactory in utils/gen trait fn body
…-gen-trait-fn-body Replace make constructor with syntaxFactory in utils/gen trait fn body
The data pointer used in the slice is never null, using assume() to tell
LLVM about it gets rid of various unneeded null checks when iterating
over the slice.
Since the snapshot compiler is still using an older LLVM version, omit
the call in stage0, because compile times explode otherwise.
Benchmarks from #18193
Fixes#18193