Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upEliminate excessive null-checks from slice iterators #21886
Conversation
rust-highfive
assigned
nikomatsakis
Feb 3, 2015
This comment has been minimized.
This comment has been minimized.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
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? |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
|
Could you add the assume to |
This comment has been minimized.
This comment has been minimized.
|
Why I originally had it in |
This comment has been minimized.
This comment has been minimized.
|
Oh, huh. I totally misread this PR. I was thinking this was in |
dotdash
force-pushed the
dotdash:fast_slice_iter
branch
from
fb2e27b
to
a2dcc1e
Feb 3, 2015
This comment has been minimized.
This comment has been minimized.
|
I suspect that means that this doesn't solve a case like http://is.gd/pteFUM, .LBB0_2:
testq %rdx, %rdx
je .LBB0_4
addl (%rdx), %eax
addq $4, %rdx
addq $-4, %rcx
jne .LBB0_2since there's no |
This comment has been minimized.
This comment has been minimized.
|
Will try to see if that helps |
jdm
reviewed
Feb 3, 2015
| @@ -427,8 +428,12 @@ impl<T> Vec<T> { | |||
| #[stable(feature = "rust1", since = "1.0.0")] | |||
| pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] { | |||
| unsafe { | |||
| let ptr = *self.ptr; | |||
| if cfg!(not(stage0)) { // NOTE remove cfg after next snapshot | |||
| assume(ptr != 0 as *mut T); | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
dotdash
Feb 3, 2015
Author
Contributor
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
force-pushed the
dotdash:fast_slice_iter
branch
from
a2dcc1e
to
e49f6d6
Feb 3, 2015
This comment has been minimized.
This comment has been minimized.
At least in this case, the |
This comment has been minimized.
This comment has been minimized.
|
@bors r+ e49f |
nikomatsakis
assigned
huonw
and unassigned
nikomatsakis
Feb 3, 2015
This comment has been minimized.
This comment has been minimized.
|
@bors: rollup |
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this pull request
Feb 4, 2015
This comment has been minimized.
This comment has been minimized.
|
@bors: rollup- |
bors
added a commit
that referenced
this pull request
Feb 4, 2015
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@huonw, that fold testcase seems to have been resolved now, it vectorizes! ( |
This comment has been minimized.
This comment has been minimized.
|
The failure seems legitimate; although, possibly a LLVM bug? |
This comment has been minimized.
This comment has been minimized.
|
Yeah, I can reproduce that in my Windows VM. |
This comment has been minimized.
This comment has been minimized.
|
Yup, LLVM bug: http://reviews.llvm.org/D7533 |
This was referenced Feb 12, 2015
dotdash
added a commit
to dotdash/rust
that referenced
this pull request
Feb 14, 2015
dotdash
added a commit
to dotdash/rust
that referenced
this pull request
Feb 14, 2015
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this pull request
Feb 17, 2015
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this pull request
Feb 18, 2015
This comment has been minimized.
This comment has been minimized.
|
LLVM update landed. Needs rebase. |
dotdash
added some commits
Feb 2, 2015
dotdash
force-pushed the
dotdash:fast_slice_iter
branch
from
e49f6d6
to
7412d1b
Feb 18, 2015
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Feb 18, 2015
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry |
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Feb 18, 2015
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry |
alexcrichton
referenced this pull request
Feb 18, 2015
Merged
Basic implementation of the string pattern API #22466
alexcrichton
added a commit
to alexcrichton/rust
that referenced
this pull request
Feb 19, 2015
bors
merged commit 7412d1b
into
rust-lang:master
Feb 19, 2015
dotdash
deleted the
dotdash:fast_slice_iter
branch
Feb 22, 2015
dotdash
added a commit
to dotdash/rust
that referenced
this pull request
Feb 22, 2015
dotdash
referenced this pull request
Feb 22, 2015
Merged
Eliminate more excessive null-checks from slice iterators #22669
Manishearth
added a commit
to Manishearth/rust
that referenced
this pull request
Feb 23, 2015
Manishearth
added a commit
to Manishearth/rust
that referenced
this pull request
Feb 23, 2015
bors
added a commit
that referenced
this pull request
Feb 24, 2015
bors
added a commit
that referenced
this pull request
Feb 27, 2015
bors
added a commit
that referenced
this pull request
Feb 28, 2015
Gankro
referenced this pull request
May 11, 2015
Merged
Handle overflow properly in core::slice #25300
This comment has been minimized.
This comment has been minimized.
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 pub fn foo(s: &[u32]) -> u32 {
s.iter().sum()
}pub fn foo(s: &[u32]) -> u32 {
s.iter().sum()
}pub fn foo(s: Vec<i32>) -> usize {
s.len()
}and even pub fn foo(_s: Vec<i32>) -> usize {
0
}produces assembly code which might have been avoided: playground::foo:
movq 8(%rdi), %rsi
testq %rsi, %rsi
je .LBB0_2
pushq %rax
movq (%rdi), %rdi
shlq $2, %rsi
movl $4, %edx
callq __rust_dealloc@PLT
addq $8, %rsp
.LBB0_2:
xorl %eax, %eax
retq |
This comment has been minimized.
This comment has been minimized.
|
In both these cases the length, rather than pointer is being checked. For the |
This comment has been minimized.
This comment has been minimized.
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! :) |
dotdash commentedFeb 3, 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
Fixes #18193