Do not visit rvalues twice.

This commit is contained in:
Camille GILLOT 2023-09-23 15:08:41 +00:00
parent d28405972f
commit afd631cc0c

View File

@ -484,11 +484,11 @@ fn visit_operand(&mut self, operand: &mut Operand<'tcx>, location: Location) {
} }
fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, location: Location) { fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, location: Location) {
self.super_statement(stmt, location);
if let StatementKind::Assign(box (_, ref mut rvalue)) = stmt.kind if let StatementKind::Assign(box (_, ref mut rvalue)) = stmt.kind
// Do not try to simplify a constant, it's already in canonical shape. // Do not try to simplify a constant, it's already in canonical shape.
&& !matches!(rvalue, Rvalue::Use(Operand::Constant(_))) && !matches!(rvalue, Rvalue::Use(Operand::Constant(_)))
&& let Some(value) = self.simplify_rvalue(rvalue, location) {
if let Some(value) = self.simplify_rvalue(rvalue, location)
{ {
if let Some(const_) = self.try_as_constant(value) { if let Some(const_) = self.try_as_constant(value) {
*rvalue = Rvalue::Use(Operand::Constant(Box::new(const_))); *rvalue = Rvalue::Use(Operand::Constant(Box::new(const_)));
@ -499,6 +499,9 @@ fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, location: Location) {
self.reused_locals.insert(local); self.reused_locals.insert(local);
} }
} }
} else {
self.super_statement(stmt, location);
}
} }
} }