Skip to content

Commit

Permalink
Run SingleUseConsts before DeadStoreElimination::Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Jul 13, 2024
1 parent 7b8c23d commit 13b29a1
Show file tree
Hide file tree
Showing 23 changed files with 123 additions and 180 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
&o1(remove_noop_landing_pads::RemoveNoopLandingPads),
&o1(simplify::SimplifyCfg::Final),
&copy_prop::CopyProp,
&single_use_consts::SingleUseConsts,
&dead_store_elimination::DeadStoreElimination::Final,
&nrvo::RenameReturnPlace,
&simplify::SimplifyLocals::Final,
Expand Down
66 changes: 22 additions & 44 deletions tests/mir-opt/const_debuginfo.main.SingleUseConsts.diff
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,31 @@
let mut _14: u32;
let mut _15: u32;
scope 1 {
- debug x => _1;
+ debug x => const 1_u8;
debug x => const 1_u8;
let _2: u8;
scope 2 {
- debug y => _2;
+ debug y => const 2_u8;
debug y => const 2_u8;
let _3: u8;
scope 3 {
- debug z => _3;
+ debug z => const 3_u8;
debug z => const 3_u8;
let _4: u8;
scope 4 {
- debug sum => _4;
+ debug sum => const 6_u8;
debug sum => const 6_u8;
let _9: &str;
scope 5 {
- debug s => _9;
+ debug s => const "hello, world!";
debug s => const "hello, world!";
let _10: (bool, bool, u32);
scope 6 {
debug f => _10;
let _11: std::option::Option<u16>;
scope 7 {
- debug o => _11;
+ debug o => const Option::<u16>::Some(99_u16);
debug o => const Option::<u16>::Some(99_u16);
let _12: Point;
scope 8 {
- debug p => _12;
+ debug p => const Point {{ x: 32_u32, y: 32_u32 }};
debug p => const Point {{ x: 32_u32, y: 32_u32 }};
let _13: u32;
scope 9 {
- debug a => _13;
+ debug a => const 64_u32;
debug a => const 64_u32;
}
}
}
Expand All @@ -56,53 +48,39 @@

bb0: {
nop;
- _1 = const 1_u8;
nop;
- _2 = const 2_u8;
nop;
- _3 = const 3_u8;
+ nop;
+ nop;
+ nop;
nop;
nop;
nop;
StorageLive(_4);
StorageLive(_5);
StorageLive(_6);
- _6 = const 1_u8;
+ nop;
nop;
StorageLive(_7);
- _7 = const 2_u8;
- _5 = const 3_u8;
+ nop;
+ nop;
nop;
nop;
StorageDead(_7);
StorageDead(_6);
StorageLive(_8);
- _8 = const 3_u8;
- _4 = const 6_u8;
+ nop;
+ nop;
nop;
nop;
StorageDead(_8);
StorageDead(_5);
StorageLive(_9);
- _9 = const "hello, world!";
+ nop;
nop;
StorageLive(_10);
_10 = (const true, const false, const 123_u32);
StorageLive(_11);
- _11 = const Option::<u16>::Some(99_u16);
+ nop;
nop;
StorageLive(_12);
- _12 = const Point {{ x: 32_u32, y: 32_u32 }};
+ nop;
nop;
StorageLive(_13);
nop;
- _14 = const 32_u32;
+ nop;
nop;
StorageLive(_15);
- _15 = const 32_u32;
- _13 = const 64_u32;
+ nop;
+ nop;
nop;
nop;
StorageDead(_15);
nop;
_0 = const ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
StorageLive(_3);
StorageLive(_4);
_4 = [_1, _1, _1];
_3 = &_4;
_2 = move _3 as &[T] (PointerCoercion(Unsize));
nop;
nop;
StorageDead(_3);
nop;
nop;
Expand All @@ -40,8 +40,11 @@

bb2: {
StorageLive(_7);
nop;
StorageLive(_8);
nop;
StorageLive(_9);
nop;
StorageDead(_9);
StorageDead(_8);
StorageDead(_7);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,19 @@
}

bb6: {
nop;
_5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>);
StorageDead(_12);
StorageDead(_6);
StorageLive(_17);
nop;
nop;
StorageDead(_17);
- StorageLive(_17);
+ nop;
_17 = (_5.0: *const [u8]);
- _4 = move _17 as *mut [u8] (PtrToPtr);
- StorageDead(_17);
+ _4 = _17 as *mut [u8] (PtrToPtr);
+ nop;
StorageDead(_5);
nop;
- _3 = move _4 as *mut u8 (PtrToPtr);
+ _3 = _17 as *mut u8 (PtrToPtr);
StorageDead(_4);
StorageDead(_3);
- StorageDead(_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@

bb1: {
StorageDead(_6);
StorageLive(_12);
nop;
nop;
StorageDead(_12);
- StorageLive(_12);
+ nop;
_12 = (_5.0: *const [u8]);
- _4 = move _12 as *mut [u8] (PtrToPtr);
- StorageDead(_12);
+ _4 = _12 as *mut [u8] (PtrToPtr);
+ nop;
StorageDead(_5);
nop;
- _3 = move _4 as *mut u8 (PtrToPtr);
+ _3 = _12 as *mut u8 (PtrToPtr);
StorageDead(_4);
StorageDead(_3);
- StorageDead(_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,19 @@
}

bb6: {
nop;
_5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>);
StorageDead(_12);
StorageDead(_6);
StorageLive(_17);
nop;
nop;
StorageDead(_17);
- StorageLive(_17);
+ nop;
_17 = (_5.0: *const [u8]);
- _4 = move _17 as *mut [u8] (PtrToPtr);
- StorageDead(_17);
+ _4 = _17 as *mut [u8] (PtrToPtr);
+ nop;
StorageDead(_5);
nop;
- _3 = move _4 as *mut u8 (PtrToPtr);
+ _3 = _17 as *mut u8 (PtrToPtr);
StorageDead(_4);
StorageDead(_3);
- StorageDead(_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
}

bb1: {
nop;
- _1 = move (_2.0: i32);
+ _1 = const 4_i32;
StorageLive(_3);
StorageLive(_4);
nop;
_4 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32];
StorageLive(_5);
_5 = const 3_usize;
_6 = const 6_usize;
Expand All @@ -45,13 +46,15 @@
}

bb2: {
nop;
- _3 = _4[_5];
+ _3 = const 3_i32;
StorageDead(_5);
StorageDead(_4);
StorageLive(_8);
StorageLive(_9);
nop;
nop;
_9 = const 42_u32;
- _8 = _9;
+ _8 = const 42_u32;
StorageDead(_9);
StorageDead(_8);
StorageDead(_3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
}

bb1: {
nop;
- _1 = move (_2.0: i32);
+ _1 = const 4_i32;
StorageLive(_3);
StorageLive(_4);
nop;
_4 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32];
StorageLive(_5);
_5 = const 3_usize;
_6 = const 6_usize;
Expand All @@ -45,13 +46,15 @@
}

bb2: {
nop;
- _3 = _4[_5];
+ _3 = const 3_i32;
StorageDead(_5);
StorageDead(_4);
StorageLive(_8);
StorageLive(_9);
nop;
nop;
_9 = const 42_u32;
- _8 = _9;
+ _8 = const 42_u32;
StorageDead(_9);
StorageDead(_8);
StorageDead(_3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
}

bb1: {
nop;
- _1 = move (_2.0: i32);
+ _1 = const 4_i32;
StorageLive(_3);
StorageLive(_4);
nop;
_4 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32];
StorageLive(_5);
_5 = const 3_usize;
_6 = const 6_usize;
Expand All @@ -45,13 +46,15 @@
}

bb2: {
nop;
- _3 = _4[_5];
+ _3 = const 3_i32;
StorageDead(_5);
StorageDead(_4);
StorageLive(_8);
StorageLive(_9);
nop;
nop;
_9 = const 42_u32;
- _8 = _9;
+ _8 = const 42_u32;
StorageDead(_9);
StorageDead(_8);
StorageDead(_3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,17 @@

fn main() -> () {
let mut _0: ();
let _1: i32;
scope 1 {
debug x => _1;
let _2: i32;
debug x => const 4_i32;
scope 2 {
debug y => _2;
let _3: u32;
debug y => const 3_i32;
scope 3 {
debug z => _3;
debug z => const 42_u32;
}
}
}

bb0: {
StorageLive(_1);
StorageLive(_2);
StorageLive(_3);
StorageDead(_3);
StorageDead(_2);
StorageDead(_1);
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,17 @@

fn main() -> () {
let mut _0: ();
let _1: i32;
scope 1 {
debug x => _1;
let _2: i32;
debug x => const 4_i32;
scope 2 {
debug y => _2;
let _3: u32;
debug y => const 3_i32;
scope 3 {
debug z => _3;
debug z => const 42_u32;
}
}
}

bb0: {
StorageLive(_1);
StorageLive(_2);
StorageLive(_3);
StorageDead(_3);
StorageDead(_2);
StorageDead(_1);
return;
}
}
Loading

0 comments on commit 13b29a1

Please sign in to comment.