diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2023-05-01 09:59:00 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2023-09-24 09:09:04 +0000 |
| commit | 1ea93998031d7bb6559ee50bb6b4d04ff4f5f035 (patch) | |
| tree | 7095d466f0ff1c87740c3530cc734b96d3a3dec7 | |
| parent | 6fa55d0aff000b8a01825dbedf9e2fdf046fd726 (diff) | |
| download | rust-1ea93998031d7bb6559ee50bb6b4d04ff4f5f035.tar.gz rust-1ea93998031d7bb6559ee50bb6b4d04ff4f5f035.zip | |
Do not check copiability.
| -rw-r--r-- | compiler/rustc_mir_transform/src/gvn.rs | 19 | ||||
| -rw-r--r-- | tests/mir-opt/gvn.rs | 4 | ||||
| -rw-r--r-- | tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff | 17 | ||||
| -rw-r--r-- | tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff | 17 |
4 files changed, 27 insertions, 30 deletions
diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index ae3352732d9..0695f9af752 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -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); diff --git a/tests/mir-opt/gvn.rs b/tests/mir-opt/gvn.rs index 33e4bdf5562..f86854fe5e1 100644 --- a/tests/mir-opt/gvn.rs +++ b/tests/mir-opt/gvn.rs @@ -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; diff --git a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff index 0034b6820f6..f44ab92f229 100644 --- a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff @@ -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); diff --git a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff index 37bc2930a0d..a4da75bd680 100644 --- a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff @@ -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); |
