Do not re-simplify SSA locals.

This commit is contained in:
Camille GILLOT 2023-10-31 19:08:36 +00:00
parent e26c9a42c6
commit 4ee01faaf0
5 changed files with 29 additions and 26 deletions

View File

@ -1015,23 +1015,32 @@ fn visit_operand(&mut self, operand: &mut Operand<'tcx>, location: Location) {
}
fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, location: Location) {
if let StatementKind::Assign(box (_, ref mut rvalue)) = stmt.kind
if let StatementKind::Assign(box (ref mut lhs, ref mut rvalue)) = stmt.kind {
self.simplify_place_projection(lhs, location);
// Do not try to simplify a constant, it's already in canonical shape.
&& !matches!(rvalue, Rvalue::Use(Operand::Constant(_)))
{
if let Some(value) = self.simplify_rvalue(rvalue, location) {
if let Some(const_) = self.try_as_constant(value) {
*rvalue = Rvalue::Use(Operand::Constant(Box::new(const_)));
} else if let Some(local) = self.try_as_local(value, location)
&& *rvalue != Rvalue::Use(Operand::Move(local.into()))
{
*rvalue = Rvalue::Use(Operand::Copy(local.into()));
self.reused_locals.insert(local);
}
if matches!(rvalue, Rvalue::Use(Operand::Constant(_))) {
return;
}
} else {
self.super_statement(stmt, location);
let value = lhs
.as_local()
.and_then(|local| self.locals[local])
.or_else(|| self.simplify_rvalue(rvalue, location));
let Some(value) = value else { return };
if let Some(const_) = self.try_as_constant(value) {
*rvalue = Rvalue::Use(Operand::Constant(Box::new(const_)));
} else if let Some(local) = self.try_as_local(value, location)
&& *rvalue != Rvalue::Use(Operand::Move(local.into()))
{
*rvalue = Rvalue::Use(Operand::Copy(local.into()));
self.reused_locals.insert(local);
}
return;
}
self.super_statement(stmt, location);
}
}

View File

@ -33,10 +33,6 @@
+ }
+
+ ALLOC1 (size: 2, align: 1) {
+ 01 02 │ ..
+ }
+
+ ALLOC2 (size: 2, align: 1) {
+ 01 02 │ ..
}

View File

@ -33,10 +33,6 @@
+ }
+
+ ALLOC1 (size: 2, align: 1) {
+ 01 02 │ ..
+ }
+
+ ALLOC2 (size: 2, align: 1) {
+ 01 02 │ ..
}

View File

@ -15,10 +15,11 @@
StorageLive(_1);
- StorageLive(_2);
- _2 = const 1_usize as &mut Never (Transmute);
- _1 = &mut (*_2);
- StorageDead(_2);
+ nop;
+ _2 = const {0x1 as &mut Never};
_1 = &mut (*_2);
- StorageDead(_2);
+ _1 = const {0x1 as &mut Never};
+ nop;
unreachable;
}

View File

@ -15,10 +15,11 @@
StorageLive(_1);
- StorageLive(_2);
- _2 = const 1_usize as &mut Never (Transmute);
- _1 = &mut (*_2);
- StorageDead(_2);
+ nop;
+ _2 = const {0x1 as &mut Never};
_1 = &mut (*_2);
- StorageDead(_2);
+ _1 = const {0x1 as &mut Never};
+ nop;
unreachable;
}