Skip to content

Commit cd4f394

Browse files
committed
Do not visit rvalues twice.
1 parent 9ce282a commit cd4f394

File tree

1 file changed

+11
-8
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+11
-8
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,20 +475,23 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
475475
}
476476

477477
fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, location: Location) {
478-
self.super_statement(stmt, location);
479478
if let StatementKind::Assign(box (_, ref mut rvalue)) = stmt.kind
480479
// Do not try to simplify a constant, it's already in canonical shape.
481480
&& !matches!(rvalue, Rvalue::Use(Operand::Constant(_)))
482-
&& let Some(value) = self.simplify_rvalue(rvalue, location)
483481
{
484-
if let Some(const_) = self.try_as_constant(value) {
485-
*rvalue = Rvalue::Use(Operand::Constant(Box::new(const_)));
486-
} else if let Some(local) = self.try_as_local(value, location)
487-
&& *rvalue != Rvalue::Use(Operand::Move(local.into()))
482+
if let Some(value) = self.simplify_rvalue(rvalue, location)
488483
{
489-
*rvalue = Rvalue::Use(Operand::Copy(local.into()));
490-
self.reused_locals.insert(local);
484+
if let Some(const_) = self.try_as_constant(value) {
485+
*rvalue = Rvalue::Use(Operand::Constant(Box::new(const_)));
486+
} else if let Some(local) = self.try_as_local(value, location)
487+
&& *rvalue != Rvalue::Use(Operand::Move(local.into()))
488+
{
489+
*rvalue = Rvalue::Use(Operand::Copy(local.into()));
490+
self.reused_locals.insert(local);
491+
}
491492
}
493+
} else {
494+
self.super_statement(stmt, location);
492495
}
493496
}
494497
}

0 commit comments

Comments
 (0)