Skip to content

Commit ad8b2e0

Browse files
committed
Add a != check to ChunkedBitSet::union.
It's a big speed win for cranelift-codegen-0.119.0.
1 parent 20cc4da commit ad8b2e0

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
@@ -804,6 +804,15 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
804804
// performance win. Also, we only need to operate on the
805805
// in-use words, hence the slicing.
806806
let num_words = num_words(chunk_domain_size as usize);
807+
808+
// If both sides are the same, nothing will change. This
809+
// case is very common and it's a pretty fast check, so
810+
// it's a performance win to do it.
811+
if self_chunk_words[0..num_words] == other_chunk_words[0..num_words] {
812+
continue;
813+
}
814+
815+
// Do a more precise "will anything change?" test.
807816
let op = |a, b| a | b;
808817
if !bitwise_changes(
809818
&self_chunk_words[0..num_words],
@@ -813,6 +822,7 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
813822
continue;
814823
}
815824

825+
// If we reach here, `self_chunk_words` is definitely changing.
816826
let self_chunk_words = Rc::make_mut(self_chunk_words);
817827
let has_changed = bitwise(
818828
&mut self_chunk_words[0..num_words],

0 commit comments

Comments
 (0)