Skip to content

Commit 25977e0

Browse files
committed
Do not visit rvalues twice.
1 parent 3e48859 commit 25977e0

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
@@ -483,20 +483,23 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
483483
}
484484

485485
fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, location: Location) {
486-
self.super_statement(stmt, location);
487486
if let StatementKind::Assign(box (_, ref mut rvalue)) = stmt.kind
488487
// Do not try to simplify a constant, it's already in canonical shape.
489488
&& !matches!(rvalue, Rvalue::Use(Operand::Constant(_)))
490-
&& let Some(value) = self.simplify_rvalue(rvalue, location)
491489
{
492-
if let Some(const_) = self.try_as_constant(value) {
493-
*rvalue = Rvalue::Use(Operand::Constant(Box::new(const_)));
494-
} else if let Some(local) = self.try_as_local(value, location)
495-
&& *rvalue != Rvalue::Use(Operand::Move(local.into()))
490+
if let Some(value) = self.simplify_rvalue(rvalue, location)
496491
{
497-
*rvalue = Rvalue::Use(Operand::Copy(local.into()));
498-
self.reused_locals.insert(local);
492+
if let Some(const_) = self.try_as_constant(value) {
493+
*rvalue = Rvalue::Use(Operand::Constant(Box::new(const_)));
494+
} else if let Some(local) = self.try_as_local(value, location)
495+
&& *rvalue != Rvalue::Use(Operand::Move(local.into()))
496+
{
497+
*rvalue = Rvalue::Use(Operand::Copy(local.into()));
498+
self.reused_locals.insert(local);
499+
}
499500
}
501+
} else {
502+
self.super_statement(stmt, location);
500503
}
501504
}
502505
}

0 commit comments

Comments
 (0)