Skip to content

Commit 55cea80

Browse files
committed
Do not visit rvalues twice.
1 parent c355637 commit 55cea80

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
@@ -476,20 +476,23 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
476476
}
477477

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

0 commit comments

Comments
 (0)