Do not check copiability.

This commit is contained in:
Camille GILLOT 2023-05-01 09:59:00 +00:00
parent 6fa55d0aff
commit 1ea9399803
4 changed files with 27 additions and 30 deletions

View File

@ -80,7 +80,6 @@ fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let mut any_replacement = false;
let mut replacer = Replacer {
tcx,
param_env,
ssa,
dominators,
state,
@ -213,7 +212,13 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
#[instrument(level = "trace", skip(self))]
fn assign(&mut self, local: Local, value: VnIndex) {
self.locals[local] = Some(value);
self.rev_locals.entry(value).or_default().push(local);
// Only register the value if its type is `Sized`, as we will emit copies of it.
let is_sized = !self.tcx.features().unsized_locals
|| self.local_decls[local].ty.is_sized(self.tcx, self.param_env);
if is_sized {
self.rev_locals.entry(value).or_default().push(local);
}
}
/// Represent the *value* which would be read from `place`.
@ -341,7 +346,6 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
struct Replacer<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
ssa: SsaLocals,
dominators: Dominators<BasicBlock>,
state: VnState<'a, 'tcx>,
@ -370,13 +374,6 @@ impl<'tcx> Replacer<'_, 'tcx> {
.copied()
.find(|&other| self.ssa.assignment_dominates(&self.dominators, other, loc))
}
fn is_local_copiable(&self, local: Local) -> bool {
let ty = self.state.local_decls[local].ty;
// We only unify copy types as we only emit copies.
// We already simplify mutable reborrows as assignments, so we also allow copying those.
ty.is_ref() || ty.is_copy_modulo_regions(self.tcx, self.param_env)
}
}
impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
@ -393,7 +390,6 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
*self.any_replacement = true;
} else if let Some(local) = self.try_as_local(value, location)
&& *operand != Operand::Move(local.into())
&& self.is_local_copiable(local)
{
*operand = Operand::Copy(local.into());
self.reused_locals.insert(local);
@ -412,7 +408,6 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
*self.any_replacement = true;
} else if let Some(local) = self.try_as_local(value, location)
&& *rvalue != Rvalue::Use(Operand::Move(local.into()))
&& self.is_local_copiable(local)
{
*rvalue = Rvalue::Use(Operand::Copy(local.into()));
self.reused_locals.insert(local);

View File

@ -34,8 +34,8 @@ fn subexpression_elimination(x: u64, y: u64, mut z: u64) {
opaque((x ^ y) + z);
opaque((x << y) + z);
opaque((x >> y) + z);
opaque(S(x)); //< This is not substituted as `S` is not `Copy`.
opaque(S(x).0); //< But this can be.
opaque(S(x));
opaque(S(x).0);
// We can substitute through an immutable reference too.
let a = &z;

View File

@ -405,17 +405,18 @@
StorageDead(_50);
StorageDead(_49);
StorageLive(_52);
StorageLive(_53);
- StorageLive(_53);
- StorageLive(_54);
- _54 = _1;
- _53 = S::<u64>(move _54);
- StorageDead(_54);
- _52 = opaque::<S<u64>>(move _53) -> [return: bb15, unwind unreachable];
+ _53 = S::<u64>(_1);
_52 = opaque::<S<u64>>(move _53) -> [return: bb15, unwind unreachable];
+ _52 = opaque::<S<u64>>(_53) -> [return: bb15, unwind unreachable];
}
bb15: {
StorageDead(_53);
- StorageDead(_53);
StorageDead(_52);
StorageLive(_55);
- StorageLive(_56);
@ -424,7 +425,7 @@
- _58 = _1;
- _57 = S::<u64>(move _58);
- StorageDead(_58);
+ _57 = S::<u64>(_1);
+ _57 = _53;
_56 = (_57.0: u64);
- _55 = opaque::<u64>(move _56) -> [return: bb16, unwind unreachable];
+ _55 = opaque::<u64>(_56) -> [return: bb16, unwind unreachable];
@ -667,17 +668,17 @@
StorageDead(_116);
StorageDead(_115);
StorageLive(_121);
StorageLive(_122);
- StorageLive(_122);
- StorageLive(_123);
- _123 = _1;
- _122 = S::<u64>(move _123);
- StorageDead(_123);
+ _122 = S::<u64>(_1);
_121 = opaque::<S<u64>>(move _122) -> [return: bb29, unwind unreachable];
- _121 = opaque::<S<u64>>(move _122) -> [return: bb29, unwind unreachable];
+ _121 = opaque::<S<u64>>(_53) -> [return: bb29, unwind unreachable];
}
bb29: {
StorageDead(_122);
- StorageDead(_122);
StorageDead(_121);
StorageLive(_124);
- StorageLive(_125);

View File

@ -405,17 +405,18 @@
StorageDead(_50);
StorageDead(_49);
StorageLive(_52);
StorageLive(_53);
- StorageLive(_53);
- StorageLive(_54);
- _54 = _1;
- _53 = S::<u64>(move _54);
- StorageDead(_54);
- _52 = opaque::<S<u64>>(move _53) -> [return: bb15, unwind continue];
+ _53 = S::<u64>(_1);
_52 = opaque::<S<u64>>(move _53) -> [return: bb15, unwind continue];
+ _52 = opaque::<S<u64>>(_53) -> [return: bb15, unwind continue];
}
bb15: {
StorageDead(_53);
- StorageDead(_53);
StorageDead(_52);
StorageLive(_55);
- StorageLive(_56);
@ -424,7 +425,7 @@
- _58 = _1;
- _57 = S::<u64>(move _58);
- StorageDead(_58);
+ _57 = S::<u64>(_1);
+ _57 = _53;
_56 = (_57.0: u64);
- _55 = opaque::<u64>(move _56) -> [return: bb16, unwind continue];
+ _55 = opaque::<u64>(_56) -> [return: bb16, unwind continue];
@ -667,17 +668,17 @@
StorageDead(_116);
StorageDead(_115);
StorageLive(_121);
StorageLive(_122);
- StorageLive(_122);
- StorageLive(_123);
- _123 = _1;
- _122 = S::<u64>(move _123);
- StorageDead(_123);
+ _122 = S::<u64>(_1);
_121 = opaque::<S<u64>>(move _122) -> [return: bb29, unwind continue];
- _121 = opaque::<S<u64>>(move _122) -> [return: bb29, unwind continue];
+ _121 = opaque::<S<u64>>(_53) -> [return: bb29, unwind continue];
}
bb29: {
StorageDead(_122);
- StorageDead(_122);
StorageDead(_121);
StorageLive(_124);
- StorageLive(_125);