Skip to content

Commit 423d13d

Browse files
nnethercoteZalathar
authored andcommitted
Add a != check to ChunkedBitSet::union.
It's a big speed win for cranelift-codegen-0.119.0.
1 parent 0524c71 commit 423d13d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

compiler/rustc_index/src/bit_set.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,15 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
801801
// performance win. Also, we only need to operate on the
802802
// in-use words, hence the slicing.
803803
let num_words = num_words(chunk_domain_size as usize);
804+
805+
// If both sides are the same, nothing will change. This
806+
// case is very common and it's a pretty fast check, so
807+
// it's a performance win to do it.
808+
if self_chunk_words[0..num_words] == other_chunk_words[0..num_words] {
809+
continue;
810+
}
811+
812+
// Do a more precise "will anything change?" test.
804813
let op = |a, b| a | b;
805814
if !bitwise_changes(
806815
&self_chunk_words[0..num_words],
@@ -810,6 +819,7 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
810819
continue;
811820
}
812821

822+
// If we reach here, `self_chunk_words` is definitely changing.
813823
let self_chunk_words = Rc::make_mut(self_chunk_words);
814824
let has_changed = bitwise(
815825
&mut self_chunk_words[0..num_words],

0 commit comments

Comments
 (0)