Skip to content

Commit 3725be6

Browse files
committed
Skip process_constant if state has no matching value.
1 parent faa646f commit 3725be6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

compiler/rustc_mir_dataflow/src/value_analysis.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -752,11 +752,15 @@ impl<'tcx> Map<'tcx> {
752752
}
753753
}
754754

755+
/// Return the range of value indices inside this place.
756+
pub fn values_inside(&self, root: PlaceIndex) -> &[ValueIndex] {
757+
let range = self.inner_values[root].clone();
758+
&self.inner_values_buffer[range]
759+
}
760+
755761
/// Invoke a function on each value in the given place and all descendants.
756762
fn for_each_value_inside(&self, root: PlaceIndex, f: &mut impl FnMut(ValueIndex)) {
757-
let range = self.inner_values[root].clone();
758-
let values = &self.inner_values_buffer[range];
759-
for &v in values {
763+
for &v in self.values_inside(root) {
760764
f(v)
761765
}
762766
}

compiler/rustc_mir_transform/src/jump_threading.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ impl<'a, 'tcx> TOFinder<'a, 'tcx> {
428428
constant: OpTy<'tcx>,
429429
state: &mut ConditionSet<'a>,
430430
) {
431+
let values_inside = self.map.values_inside(lhs);
432+
if !state.iter().any(|cond| values_inside.contains(&cond.place)) {
433+
return;
434+
}
431435
self.map.for_each_projection_value(
432436
lhs,
433437
constant,

0 commit comments

Comments
 (0)