Skip to content

Commit 3f66e3a

Browse files
committed
Skip process_constant if state has no matching value.
1 parent 5087f44 commit 3f66e3a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@ impl<'a, 'tcx> TOFinder<'a, 'tcx> {
355355
return;
356356
}
357357
let mut places_to_exclude = FxHashSet::default();
358+
//with_capacity(
359+
// self.map.find_value(place.as_ref()).map_or(
360+
// 0,
361+
// |place| self.map.values_inside(place).len()
362+
// )
363+
//);
358364
self.map.for_each_aliasing_place(place.as_ref(), extra_elem, &mut |vi| {
359365
places_to_exclude.insert(vi);
360366
});
@@ -429,6 +435,10 @@ impl<'a, 'tcx> TOFinder<'a, 'tcx> {
429435
constant: OpTy<'tcx>,
430436
state: &mut ConditionSet<'a>,
431437
) {
438+
let values_inside = self.map.values_inside(lhs);
439+
if !state.iter().any(|cond| values_inside.contains(&cond.place)) {
440+
return;
441+
}
432442
self.map.for_each_projection_value(
433443
lhs,
434444
constant,

0 commit comments

Comments
 (0)