Skip to content

Commit f64c307

Browse files
committed
Run SingleUseConsts before DeadStoreElimination::Initial
1 parent 7b8c23d commit f64c307

File tree

28 files changed

+150
-153
lines changed

28 files changed

+150
-153
lines changed

compiler/rustc_mir_transform/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,11 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
593593
&multiple_return_terminators::MultipleReturnTerminators,
594594
&instsimplify::InstSimplify,
595595
&simplify::SimplifyLocals::BeforeConstProp,
596-
&dead_store_elimination::DeadStoreElimination::Initial,
597596
&gvn::GVN,
598597
&simplify::SimplifyLocals::AfterGVN,
599598
&dataflow_const_prop::DataflowConstProp,
600599
&single_use_consts::SingleUseConsts,
600+
&dead_store_elimination::DeadStoreElimination::Initial,
601601
&o1(simplify_branches::SimplifyConstCondition::AfterConstProp),
602602
&jump_threading::JumpThreading,
603603
&early_otherwise_branch::EarlyOtherwiseBranch,

tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
StorageLive(_3);
2727
StorageLive(_4);
2828
_4 = [_1, _1, _1];
29-
_3 = &_4;
30-
_2 = move _3 as &[T] (PointerCoercion(Unsize));
29+
nop;
30+
nop;
3131
StorageDead(_3);
3232
nop;
3333
nop;
@@ -40,8 +40,11 @@
4040

4141
bb2: {
4242
StorageLive(_7);
43+
nop;
4344
StorageLive(_8);
45+
nop;
4446
StorageLive(_9);
47+
nop;
4548
StorageDead(_9);
4649
StorageDead(_8);
4750
StorageDead(_7);

tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
StorageLive(_3);
2727
StorageLive(_4);
2828
_4 = [_1, _1, _1];
29-
_3 = &_4;
30-
_2 = move _3 as &[T] (PointerCoercion(Unsize));
29+
nop;
30+
nop;
3131
StorageDead(_3);
3232
nop;
3333
nop;
@@ -40,8 +40,11 @@
4040

4141
bb2: {
4242
StorageLive(_7);
43+
nop;
4344
StorageLive(_8);
45+
nop;
4446
StorageLive(_9);
47+
nop;
4548
StorageDead(_9);
4649
StorageDead(_8);
4750
StorageDead(_7);

tests/mir-opt/pre-codegen/derived_ord.{impl#0}-partial_cmp.PreCodegen.after.mir

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ fn <impl at $DIR/derived_ord.rs:6:10: 6:20>::partial_cmp(_1: &MultiField, _2: &M
66
let mut _0: std::option::Option<std::cmp::Ordering>;
77
let mut _6: std::option::Option<std::cmp::Ordering>;
88
let mut _7: i8;
9+
let _11: std::option::Option<std::cmp::Ordering>;
910
scope 1 {
10-
debug cmp => _6;
11+
debug cmp => _11;
1112
}
1213
scope 2 (inlined std::cmp::impls::<impl PartialOrd for char>::partial_cmp) {
1314
let mut _3: char;
@@ -48,7 +49,9 @@ fn <impl at $DIR/derived_ord.rs:6:10: 6:20>::partial_cmp(_1: &MultiField, _2: &M
4849
}
4950

5051
bb2: {
52+
StorageLive(_11);
5153
_0 = _6;
54+
StorageDead(_11);
5255
goto -> bb3;
5356
}
5457

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff

+10-6
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,19 @@
100100
}
101101

102102
bb6: {
103-
nop;
103+
_5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>);
104104
StorageDead(_12);
105105
StorageDead(_6);
106-
StorageLive(_17);
107-
nop;
108-
nop;
109-
StorageDead(_17);
106+
- StorageLive(_17);
107+
+ nop;
108+
_17 = (_5.0: *const [u8]);
109+
- _4 = move _17 as *mut [u8] (PtrToPtr);
110+
- StorageDead(_17);
111+
+ _4 = _17 as *mut [u8] (PtrToPtr);
112+
+ nop;
110113
StorageDead(_5);
111-
nop;
114+
- _3 = move _4 as *mut u8 (PtrToPtr);
115+
+ _3 = _17 as *mut u8 (PtrToPtr);
112116
StorageDead(_4);
113117
StorageDead(_3);
114118
- StorageDead(_1);

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff

+9-5
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,16 @@
4545

4646
bb1: {
4747
StorageDead(_6);
48-
StorageLive(_12);
49-
nop;
50-
nop;
51-
StorageDead(_12);
48+
- StorageLive(_12);
49+
+ nop;
50+
_12 = (_5.0: *const [u8]);
51+
- _4 = move _12 as *mut [u8] (PtrToPtr);
52+
- StorageDead(_12);
53+
+ _4 = _12 as *mut [u8] (PtrToPtr);
54+
+ nop;
5255
StorageDead(_5);
53-
nop;
56+
- _3 = move _4 as *mut u8 (PtrToPtr);
57+
+ _3 = _12 as *mut u8 (PtrToPtr);
5458
StorageDead(_4);
5559
StorageDead(_3);
5660
- StorageDead(_1);

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff

+10-6
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,19 @@
100100
}
101101

102102
bb6: {
103-
nop;
103+
_5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>);
104104
StorageDead(_12);
105105
StorageDead(_6);
106-
StorageLive(_17);
107-
nop;
108-
nop;
109-
StorageDead(_17);
106+
- StorageLive(_17);
107+
+ nop;
108+
_17 = (_5.0: *const [u8]);
109+
- _4 = move _17 as *mut [u8] (PtrToPtr);
110+
- StorageDead(_17);
111+
+ _4 = _17 as *mut [u8] (PtrToPtr);
112+
+ nop;
110113
StorageDead(_5);
111-
nop;
114+
- _3 = move _4 as *mut u8 (PtrToPtr);
115+
+ _3 = _17 as *mut u8 (PtrToPtr);
112116
StorageDead(_4);
113117
StorageDead(_3);
114118
- StorageDead(_1);

tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff

+9-5
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,16 @@
4545

4646
bb1: {
4747
StorageDead(_6);
48-
StorageLive(_12);
49-
nop;
50-
nop;
51-
StorageDead(_12);
48+
- StorageLive(_12);
49+
+ nop;
50+
_12 = (_5.0: *const [u8]);
51+
- _4 = move _12 as *mut [u8] (PtrToPtr);
52+
- StorageDead(_12);
53+
+ _4 = _12 as *mut [u8] (PtrToPtr);
54+
+ nop;
5255
StorageDead(_5);
53-
nop;
56+
- _3 = move _4 as *mut u8 (PtrToPtr);
57+
+ _3 = _12 as *mut u8 (PtrToPtr);
5458
StorageDead(_4);
5559
StorageDead(_3);
5660
- StorageDead(_1);

tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-abort.diff

+8-5
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
}
3232

3333
bb1: {
34-
nop;
34+
- _1 = move (_2.0: i32);
35+
+ _1 = const 4_i32;
3536
StorageLive(_3);
3637
StorageLive(_4);
37-
nop;
38+
_4 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32];
3839
StorageLive(_5);
3940
_5 = const 3_usize;
4041
_6 = const 6_usize;
@@ -45,13 +46,15 @@
4546
}
4647

4748
bb2: {
48-
nop;
49+
- _3 = _4[_5];
50+
+ _3 = const 3_i32;
4951
StorageDead(_5);
5052
StorageDead(_4);
5153
StorageLive(_8);
5254
StorageLive(_9);
53-
nop;
54-
nop;
55+
_9 = const 42_u32;
56+
- _8 = _9;
57+
+ _8 = const 42_u32;
5558
StorageDead(_9);
5659
StorageDead(_8);
5760
StorageDead(_3);

tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.32bit.panic-unwind.diff

+8-5
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
}
3232

3333
bb1: {
34-
nop;
34+
- _1 = move (_2.0: i32);
35+
+ _1 = const 4_i32;
3536
StorageLive(_3);
3637
StorageLive(_4);
37-
nop;
38+
_4 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32];
3839
StorageLive(_5);
3940
_5 = const 3_usize;
4041
_6 = const 6_usize;
@@ -45,13 +46,15 @@
4546
}
4647

4748
bb2: {
48-
nop;
49+
- _3 = _4[_5];
50+
+ _3 = const 3_i32;
4951
StorageDead(_5);
5052
StorageDead(_4);
5153
StorageLive(_8);
5254
StorageLive(_9);
53-
nop;
54-
nop;
55+
_9 = const 42_u32;
56+
- _8 = _9;
57+
+ _8 = const 42_u32;
5558
StorageDead(_9);
5659
StorageDead(_8);
5760
StorageDead(_3);

tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.64bit.panic-abort.diff

+8-5
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
}
3232

3333
bb1: {
34-
nop;
34+
- _1 = move (_2.0: i32);
35+
+ _1 = const 4_i32;
3536
StorageLive(_3);
3637
StorageLive(_4);
37-
nop;
38+
_4 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32];
3839
StorageLive(_5);
3940
_5 = const 3_usize;
4041
_6 = const 6_usize;
@@ -45,13 +46,15 @@
4546
}
4647

4748
bb2: {
48-
nop;
49+
- _3 = _4[_5];
50+
+ _3 = const 3_i32;
4951
StorageDead(_5);
5052
StorageDead(_4);
5153
StorageLive(_8);
5254
StorageLive(_9);
53-
nop;
54-
nop;
55+
_9 = const 42_u32;
56+
- _8 = _9;
57+
+ _8 = const 42_u32;
5558
StorageDead(_9);
5659
StorageDead(_8);
5760
StorageDead(_3);

tests/mir-opt/pre-codegen/optimizes_into_variable.main.GVN.64bit.panic-unwind.diff

+8-5
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
}
3232

3333
bb1: {
34-
nop;
34+
- _1 = move (_2.0: i32);
35+
+ _1 = const 4_i32;
3536
StorageLive(_3);
3637
StorageLive(_4);
37-
nop;
38+
_4 = [const 0_i32, const 1_i32, const 2_i32, const 3_i32, const 4_i32, const 5_i32];
3839
StorageLive(_5);
3940
_5 = const 3_usize;
4041
_6 = const 6_usize;
@@ -45,13 +46,15 @@
4546
}
4647

4748
bb2: {
48-
nop;
49+
- _3 = _4[_5];
50+
+ _3 = const 3_i32;
4951
StorageDead(_5);
5052
StorageDead(_4);
5153
StorageLive(_8);
5254
StorageLive(_9);
53-
nop;
54-
nop;
55+
_9 = const 42_u32;
56+
- _8 = _9;
57+
+ _8 = const 42_u32;
5558
StorageDead(_9);
5659
StorageDead(_8);
5760
StorageDead(_3);

tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-abort.mir

+3-12
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,17 @@
22

33
fn main() -> () {
44
let mut _0: ();
5-
let _1: i32;
65
scope 1 {
7-
debug x => _1;
8-
let _2: i32;
6+
debug x => const 4_i32;
97
scope 2 {
10-
debug y => _2;
11-
let _3: u32;
8+
debug y => const 3_i32;
129
scope 3 {
13-
debug z => _3;
10+
debug z => const 42_u32;
1411
}
1512
}
1613
}
1714

1815
bb0: {
19-
StorageLive(_1);
20-
StorageLive(_2);
21-
StorageLive(_3);
22-
StorageDead(_3);
23-
StorageDead(_2);
24-
StorageDead(_1);
2516
return;
2617
}
2718
}

tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.32bit.panic-unwind.mir

+3-12
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,17 @@
22

33
fn main() -> () {
44
let mut _0: ();
5-
let _1: i32;
65
scope 1 {
7-
debug x => _1;
8-
let _2: i32;
6+
debug x => const 4_i32;
97
scope 2 {
10-
debug y => _2;
11-
let _3: u32;
8+
debug y => const 3_i32;
129
scope 3 {
13-
debug z => _3;
10+
debug z => const 42_u32;
1411
}
1512
}
1613
}
1714

1815
bb0: {
19-
StorageLive(_1);
20-
StorageLive(_2);
21-
StorageLive(_3);
22-
StorageDead(_3);
23-
StorageDead(_2);
24-
StorageDead(_1);
2516
return;
2617
}
2718
}

tests/mir-opt/pre-codegen/optimizes_into_variable.main.PreCodegen.after.64bit.panic-abort.mir

+3-12
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,17 @@
22

33
fn main() -> () {
44
let mut _0: ();
5-
let _1: i32;
65
scope 1 {
7-
debug x => _1;
8-
let _2: i32;
6+
debug x => const 4_i32;
97
scope 2 {
10-
debug y => _2;
11-
let _3: u32;
8+
debug y => const 3_i32;
129
scope 3 {
13-
debug z => _3;
10+
debug z => const 42_u32;
1411
}
1512
}
1613
}
1714

1815
bb0: {
19-
StorageLive(_1);
20-
StorageLive(_2);
21-
StorageLive(_3);
22-
StorageDead(_3);
23-
StorageDead(_2);
24-
StorageDead(_1);
2516
return;
2617
}
2718
}

0 commit comments

Comments
 (0)