diff options
| author | bors <bors@rust-lang.org> | 2023-05-08 14:23:13 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-05-08 14:23:13 +0000 |
| commit | a0111af531178e48375f14f838d7a2298524067c (patch) | |
| tree | 96a4bc428f299af2cc8a5e408e76b5689ca7409e /compiler/rustc_mir_transform/src | |
| parent | ce042889f7f0d687368a9704eff64cf9542bac6d (diff) | |
| parent | a8988519d508cf89b96d18aaa9ace4e0bcd67621 (diff) | |
| download | rust-a0111af531178e48375f14f838d7a2298524067c.tar.gz rust-a0111af531178e48375f14f838d7a2298524067c.zip | |
Auto merge of #110824 - cjgillot:const-prop-index, r=JakobDegen,oli-obk
ConstProp into PlaceElem::Index. Noticed this while looking at keccak output MIR. This pass aims to replace `ProjectionElem::Index` with `ProjectionElem::ConstantIndex` during ConstProp. r? `@ghost`
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/const_prop.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 7f995c69a48..a5d18fff89b 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -806,6 +806,24 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> { } } + fn process_projection_elem( + &mut self, + elem: PlaceElem<'tcx>, + _: Location, + ) -> Option<PlaceElem<'tcx>> { + if let PlaceElem::Index(local) = elem + && let Some(value) = self.get_const(local.into()) + && self.should_const_prop(&value) + && let interpret::Operand::Immediate(interpret::Immediate::Scalar(scalar)) = *value + && let Ok(offset) = scalar.to_target_usize(&self.tcx) + && let Some(min_length) = offset.checked_add(1) + { + Some(PlaceElem::ConstantIndex { offset, min_length, from_end: false }) + } else { + None + } + } + fn visit_assign( &mut self, place: &mut Place<'tcx>, |
