Skip to content

Commit 0260333

Browse files
committed
Fix major compile time regression
The assume intrinsic has a strong, negative impact on compile times, so we're currently only using it in places where LLVM can simplify it to nonnull metadata on a load intruction. Unfortunately a recent change that fixed invalid assume calls introduce new assume calls for which this simplification can not happen, leading to a massive regression in compile times in certain cases. Moving the assumptions from the middle of the function to the beginning allows the simplification to happen again, bringing compile times back to their old levels. Fixes #25393
1 parent b1bd3a3 commit 0260333

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/libcore/slice.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -665,14 +665,14 @@ macro_rules! iterator {
665665
#[inline]
666666
fn next(&mut self) -> Option<$elem> {
667667
// could be implemented with slices, but this avoids bounds checks
668-
if self.ptr == self.end {
669-
None
670-
} else {
671-
unsafe {
672-
if mem::size_of::<T>() != 0 {
673-
::intrinsics::assume(!self.ptr.is_null());
674-
::intrinsics::assume(!self.end.is_null());
675-
}
668+
unsafe {
669+
if mem::size_of::<T>() != 0 {
670+
assume(!self.ptr.is_null());
671+
assume(!self.end.is_null());
672+
}
673+
if self.ptr == self.end {
674+
None
675+
} else {
676676
let old = self.ptr;
677677
self.ptr = slice_offset!(self.ptr, 1);
678678
Some(slice_ref!(old))
@@ -710,15 +710,15 @@ macro_rules! iterator {
710710
#[inline]
711711
fn next_back(&mut self) -> Option<$elem> {
712712
// could be implemented with slices, but this avoids bounds checks
713-
if self.end == self.ptr {
714-
None
715-
} else {
716-
unsafe {
713+
unsafe {
714+
if mem::size_of::<T>() != 0 {
715+
assume(!self.ptr.is_null());
716+
assume(!self.end.is_null());
717+
}
718+
if self.end == self.ptr {
719+
None
720+
} else {
717721
self.end = slice_offset!(self.end, -1);
718-
if mem::size_of::<T>() != 0 {
719-
::intrinsics::assume(!self.ptr.is_null());
720-
::intrinsics::assume(!self.end.is_null());
721-
}
722722
Some(slice_ref!(self.end))
723723
}
724724
}

0 commit comments

Comments
 (0)