diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2023-12-24 13:00:48 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2024-01-07 13:54:05 +0000 |
| commit | 7e39100586d717f5a350eb8704bcd8938d09419c (patch) | |
| tree | 3c6030d6108a9fc00cd089bd4bca44998380c8ea /compiler/rustc_mir_transform/src | |
| parent | 4ee01faaf074f3a985bb7325f2209f9ee224cb5e (diff) | |
| download | rust-7e39100586d717f5a350eb8704bcd8938d09419c.tar.gz rust-7e39100586d717f5a350eb8704bcd8938d09419c.zip | |
Avoid recording no-op replacements.
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/gvn.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index e8b86d1327d..dc3af038d80 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -637,6 +637,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { if place.is_indirect() && let Some(base) = self.locals[place.local] && let Some(new_local) = self.try_as_local(base, location) + && place.local != new_local { place.local = new_local; self.reused_locals.insert(new_local); @@ -646,8 +647,8 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { for i in 0..projection.len() { let elem = projection[i]; - if let ProjectionElem::Index(idx) = elem - && let Some(idx) = self.locals[idx] + if let ProjectionElem::Index(idx_local) = elem + && let Some(idx) = self.locals[idx_local] { if let Some(offset) = self.evaluated[idx].as_ref() && let Ok(offset) = self.ecx.read_target_usize(offset) @@ -655,9 +656,11 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { { projection.to_mut()[i] = ProjectionElem::ConstantIndex { offset, min_length, from_end: false }; - } else if let Some(new_idx) = self.try_as_local(idx, location) { - projection.to_mut()[i] = ProjectionElem::Index(new_idx); - self.reused_locals.insert(new_idx); + } else if let Some(new_idx_local) = self.try_as_local(idx, location) + && idx_local != new_idx_local + { + projection.to_mut()[i] = ProjectionElem::Index(new_idx_local); + self.reused_locals.insert(new_idx_local); } } } |
