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 Jun 29, 2024
1 parent 7b8c23d commit f64c307
Show file tree
Hide file tree
Showing 28 changed files with 150 additions and 153 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,11 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
&multiple_return_terminators::MultipleReturnTerminators,
&instsimplify::InstSimplify,
&simplify::SimplifyLocals::BeforeConstProp,
&dead_store_elimination::DeadStoreElimination::Initial,
&gvn::GVN,
&simplify::SimplifyLocals::AfterGVN,
&dataflow_const_prop::DataflowConstProp,
&single_use_consts::SingleUseConsts,
&dead_store_elimination::DeadStoreElimination::Initial,
&o1(simplify_branches::SimplifyConstCondition::AfterConstProp),
&jump_threading::JumpThreading,
&early_otherwise_branch::EarlyOtherwiseBranch,
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 @@ -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 @@ -6,8 +6,9 @@ fn <impl at $DIR/derived_ord.rs:6:10: 6:20>::partial_cmp(_1: &MultiField, _2: &M
let mut _0: std::option::Option<std::cmp::Ordering>;
let mut _6: std::option::Option<std::cmp::Ordering>;
let mut _7: i8;
let _11: std::option::Option<std::cmp::Ordering>;
scope 1 {
debug cmp => _6;
debug cmp => _11;
}
scope 2 (inlined std::cmp::impls::<impl PartialOrd for char>::partial_cmp) {
let mut _3: char;
Expand Down Expand Up @@ -48,7 +49,9 @@ fn <impl at $DIR/derived_ord.rs:6:10: 6:20>::partial_cmp(_1: &MultiField, _2: &M
}

bb2: {
StorageLive(_11);
_0 = _6;
StorageDead(_11);
goto -> bb3;
}

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 @@ -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 @@ -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 @@ -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;
}
}
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 f64c307

Please sign in to comment.