Skip to content

Commit 22eae62

Browse files
committed
Replace ConstProp by DataflowConstProp.
1 parent c06b2b9 commit 22eae62

File tree

137 files changed

+361
-995
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+361
-995
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

+13-541
Large diffs are not rendered by default.

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ use crate::MirPass;
2626
const BLOCK_LIMIT: usize = 100;
2727
const PLACE_LIMIT: usize = 100;
2828

29-
pub struct DataflowConstProp;
29+
pub struct ConstProp;
3030

31-
impl<'tcx> MirPass<'tcx> for DataflowConstProp {
31+
impl<'tcx> MirPass<'tcx> for ConstProp {
3232
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
33-
sess.mir_opt_level() >= 3
33+
sess.mir_opt_level() >= 2
3434
}
3535

3636
#[instrument(skip_all level = "debug")]

compiler/rustc_mir_transform/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> {
364364
pm::run_passes(
365365
tcx,
366366
&mut body,
367-
&[&const_prop::ConstProp],
367+
&[&dataflow_const_prop::ConstProp],
368368
Some(MirPhase::Runtime(RuntimePhase::Optimized)),
369369
);
370370
}
@@ -565,8 +565,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
565565
// destroy the SSA property. It should still happen before const-propagation, so the
566566
// latter pass will leverage the created opportunities.
567567
&separate_const_switch::SeparateConstSwitch,
568-
&const_prop::ConstProp,
569-
&dataflow_const_prop::DataflowConstProp,
568+
&dataflow_const_prop::ConstProp,
570569
//
571570
// Const-prop runs unconditionally, but doesn't mutate the MIR at mir-opt-level=0.
572571
&const_debuginfo::ConstDebugInfo,

tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-abort.diff

+4-6
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@
1818
_2 = [const 0_u32, const 1_u32, const 2_u32, const 3_u32];
1919
StorageLive(_3);
2020
_3 = const 2_usize;
21-
- _4 = Len(_2);
21+
_4 = Len(_2);
2222
- _5 = Lt(_3, _4);
2323
- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind unreachable];
24-
+ _4 = const 4_usize;
25-
+ _5 = const true;
26-
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind unreachable];
24+
+ _5 = Lt(const 2_usize, _4);
25+
+ assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, const 2_usize) -> [success: bb1, unwind unreachable];
2726
}
2827

2928
bb1: {
30-
- _1 = _2[_3];
31-
+ _1 = const 2_u32;
29+
_1 = _2[_3];
3230
StorageDead(_3);
3331
StorageDead(_2);
3432
_0 = const ();

tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-unwind.diff

+4-6
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@
1818
_2 = [const 0_u32, const 1_u32, const 2_u32, const 3_u32];
1919
StorageLive(_3);
2020
_3 = const 2_usize;
21-
- _4 = Len(_2);
21+
_4 = Len(_2);
2222
- _5 = Lt(_3, _4);
2323
- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind continue];
24-
+ _4 = const 4_usize;
25-
+ _5 = const true;
26-
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind continue];
24+
+ _5 = Lt(const 2_usize, _4);
25+
+ assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, const 2_usize) -> [success: bb1, unwind continue];
2726
}
2827

2928
bb1: {
30-
- _1 = _2[_3];
31-
+ _1 = const 2_u32;
29+
_1 = _2[_3];
3230
StorageDead(_3);
3331
StorageDead(_2);
3432
_0 = const ();

tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-abort.diff

+4-6
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@
1818
_2 = [const 0_u32, const 1_u32, const 2_u32, const 3_u32];
1919
StorageLive(_3);
2020
_3 = const 2_usize;
21-
- _4 = Len(_2);
21+
_4 = Len(_2);
2222
- _5 = Lt(_3, _4);
2323
- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind unreachable];
24-
+ _4 = const 4_usize;
25-
+ _5 = const true;
26-
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind unreachable];
24+
+ _5 = Lt(const 2_usize, _4);
25+
+ assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, const 2_usize) -> [success: bb1, unwind unreachable];
2726
}
2827

2928
bb1: {
30-
- _1 = _2[_3];
31-
+ _1 = const 2_u32;
29+
_1 = _2[_3];
3230
StorageDead(_3);
3331
StorageDead(_2);
3432
_0 = const ();

tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-unwind.diff

+4-6
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@
1818
_2 = [const 0_u32, const 1_u32, const 2_u32, const 3_u32];
1919
StorageLive(_3);
2020
_3 = const 2_usize;
21-
- _4 = Len(_2);
21+
_4 = Len(_2);
2222
- _5 = Lt(_3, _4);
2323
- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind continue];
24-
+ _4 = const 4_usize;
25-
+ _5 = const true;
26-
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind continue];
24+
+ _5 = Lt(const 2_usize, _4);
25+
+ assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, const 2_usize) -> [success: bb1, unwind continue];
2726
}
2827

2928
bb1: {
30-
- _1 = _2[_3];
31-
+ _1 = const 2_u32;
29+
_1 = _2[_3];
3230
StorageDead(_3);
3331
StorageDead(_2);
3432
_0 = const ();

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-abort.diff

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
4242
}
4343

4444
bb1: {
45-
- _5 = (*_1)[_6];
46-
+ _5 = (*_1)[3 of 4];
45+
_5 = (*_1)[_6];
4746
StorageDead(_6);
4847
_0 = const ();
4948
StorageDead(_5);

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-unwind.diff

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
4242
}
4343

4444
bb1: {
45-
- _5 = (*_1)[_6];
46-
+ _5 = (*_1)[3 of 4];
45+
_5 = (*_1)[_6];
4746
StorageDead(_6);
4847
_0 = const ();
4948
StorageDead(_5);

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-abort.diff

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
4242
}
4343

4444
bb1: {
45-
- _5 = (*_1)[_6];
46-
+ _5 = (*_1)[3 of 4];
45+
_5 = (*_1)[_6];
4746
StorageDead(_6);
4847
_0 = const ();
4948
StorageDead(_5);

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-unwind.diff

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
4242
}
4343

4444
bb1: {
45-
- _5 = (*_1)[_6];
46-
+ _5 = (*_1)[3 of 4];
45+
_5 = (*_1)[_6];
4746
StorageDead(_6);
4847
_0 = const ();
4948
StorageDead(_5);

tests/mir-opt/const_prop/boolean_identities.test.ConstProp.diff

+3-6
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@
1212

1313
bb0: {
1414
StorageLive(_3);
15-
- _3 = BitOr(_2, const true);
16-
+ _3 = const true;
15+
_3 = BitOr(_2, const true);
1716
StorageLive(_5);
18-
- _5 = BitAnd(_1, const false);
19-
- _0 = BitAnd(move _3, move _5);
20-
+ _5 = const false;
21-
+ _0 = const false;
17+
_5 = BitAnd(_1, const false);
18+
_0 = BitAnd(move _3, move _5);
2219
StorageDead(_5);
2320
StorageDead(_3);
2421
return;

tests/mir-opt/const_prop/boxes.main.ConstProp.panic-abort.diff

+3-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@
2222
StorageLive(_1);
2323
StorageLive(_2);
2424
StorageLive(_3);
25-
- _4 = SizeOf(i32);
26-
- _5 = AlignOf(i32);
27-
- _6 = alloc::alloc::exchange_malloc(move _4, move _5) -> [return: bb1, unwind unreachable];
28-
+ _4 = const 4_usize;
29-
+ _5 = const 4_usize;
30-
+ _6 = alloc::alloc::exchange_malloc(const 4_usize, const 4_usize) -> [return: bb1, unwind unreachable];
25+
_4 = SizeOf(i32);
26+
_5 = AlignOf(i32);
27+
_6 = alloc::alloc::exchange_malloc(move _4, move _5) -> [return: bb1, unwind unreachable];
3128
}
3229

3330
bb1: {

tests/mir-opt/const_prop/boxes.main.ConstProp.panic-unwind.diff

+3-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@
2222
StorageLive(_1);
2323
StorageLive(_2);
2424
StorageLive(_3);
25-
- _4 = SizeOf(i32);
26-
- _5 = AlignOf(i32);
27-
- _6 = alloc::alloc::exchange_malloc(move _4, move _5) -> [return: bb1, unwind continue];
28-
+ _4 = const 4_usize;
29-
+ _5 = const 4_usize;
30-
+ _6 = alloc::alloc::exchange_malloc(const 4_usize, const 4_usize) -> [return: bb1, unwind continue];
25+
_4 = SizeOf(i32);
26+
_5 = AlignOf(i32);
27+
_6 = alloc::alloc::exchange_malloc(move _4, move _5) -> [return: bb1, unwind continue];
3128
}
3229

3330
bb1: {

tests/mir-opt/const_prop/cast.main.ConstProp.diff

+25
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@
44
fn main() -> () {
55
let mut _0: ();
66
let _1: u32;
7+
let mut _5: u8;
8+
let mut _6: i32;
79
scope 1 {
810
debug x => _1;
911
let _2: u8;
1012
scope 2 {
1113
debug y => _2;
14+
let _3: i32;
15+
scope 3 {
16+
debug a => _3;
17+
let _4: u8;
18+
scope 4 {
19+
debug b => _4;
20+
}
21+
}
1222
}
1323
}
1424

@@ -19,7 +29,22 @@
1929
StorageLive(_2);
2030
- _2 = const 42_u32 as u8 (IntToInt);
2131
+ _2 = const 42_u8;
32+
StorageLive(_3);
33+
_3 = const 257_i32;
34+
StorageLive(_4);
35+
StorageLive(_5);
36+
StorageLive(_6);
37+
- _6 = _3;
38+
- _5 = move _6 as u8 (IntToInt);
39+
+ _6 = const 257_i32;
40+
+ _5 = const 1_u8;
41+
StorageDead(_6);
42+
- _4 = Add(move _5, const 1_u8);
43+
+ _4 = const 2_u8;
44+
StorageDead(_5);
2245
_0 = const ();
46+
StorageDead(_4);
47+
StorageDead(_3);
2348
StorageDead(_2);
2449
StorageDead(_1);
2550
return;

tests/mir-opt/const_prop/cast.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
fn main() {
55
let x = 42u8 as u32;
6-
76
let y = 42u32 as u8;
7+
8+
let a = 257;
9+
let b = a as u8 + 1;
810
}

tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.panic-abort.diff renamed to tests/mir-opt/const_prop/checked.main.ConstProp.panic-abort.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `main` before DataflowConstProp
2-
+ // MIR for `main` after DataflowConstProp
1+
- // MIR for `main` before ConstProp
2+
+ // MIR for `main` after ConstProp
33

44
fn main() -> () {
55
let mut _0: ();

tests/mir-opt/dataflow-const-prop/checked.main.DataflowConstProp.panic-unwind.diff renamed to tests/mir-opt/const_prop/checked.main.ConstProp.panic-unwind.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `main` before DataflowConstProp
2-
+ // MIR for `main` after DataflowConstProp
1+
- // MIR for `main` before ConstProp
2+
+ // MIR for `main` after ConstProp
33

44
fn main() -> () {
55
let mut _0: ();

tests/mir-opt/dataflow-const-prop/checked.rs renamed to tests/mir-opt/const_prop/checked.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
2-
// unit-test: DataflowConstProp
2+
// unit-test: ConstProp
33
// compile-flags: -Coverflow-checks=on
44

5-
// EMIT_MIR checked.main.DataflowConstProp.diff
5+
// EMIT_MIR checked.main.ConstProp.diff
66
#[allow(arithmetic_overflow)]
77
fn main() {
88
let a = 1;

tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-abort.diff

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111

1212
bb0: {
1313
StorageLive(_1);
14-
- _2 = CheckedAdd(const 1_u32, const 1_u32);
14+
_2 = CheckedAdd(const 1_u32, const 1_u32);
1515
- assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 1_u32, const 1_u32) -> [success: bb1, unwind unreachable];
16-
+ _2 = const (2_u32, false);
1716
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 1_u32, const 1_u32) -> [success: bb1, unwind unreachable];
1817
}
1918

tests/mir-opt/const_prop/checked_add.main.ConstProp.panic-unwind.diff

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111

1212
bb0: {
1313
StorageLive(_1);
14-
- _2 = CheckedAdd(const 1_u32, const 1_u32);
14+
_2 = CheckedAdd(const 1_u32, const 1_u32);
1515
- assert(!move (_2.1: bool), "attempt to compute `{} + {}`, which would overflow", const 1_u32, const 1_u32) -> [success: bb1, unwind continue];
16-
+ _2 = const (2_u32, false);
1716
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 1_u32, const 1_u32) -> [success: bb1, unwind continue];
1817
}
1918

tests/mir-opt/const_prop/control_flow_simplification.hello.ConstProp.panic-abort.diff

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
bb0: {
1010
StorageLive(_1);
11-
- _1 = const _;
11+
_1 = const _;
1212
- switchInt(move _1) -> [0: bb2, otherwise: bb1];
13-
+ _1 = const false;
1413
+ switchInt(const false) -> [0: bb2, otherwise: bb1];
1514
}
1615

tests/mir-opt/const_prop/control_flow_simplification.hello.ConstProp.panic-unwind.diff

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
bb0: {
1010
StorageLive(_1);
11-
- _1 = const _;
11+
_1 = const _;
1212
- switchInt(move _1) -> [0: bb2, otherwise: bb1];
13-
+ _1 = const false;
1413
+ switchInt(const false) -> [0: bb2, otherwise: bb1];
1514
}
1615

tests/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
StorageLive(_1);
1818
StorageLive(_2);
1919
StorageLive(_3);
20-
- _3 = Option::<bool>::Some(const true);
20+
_3 = Option::<bool>::Some(const true);
2121
- _4 = discriminant(_3);
2222
- switchInt(move _4) -> [1: bb1, otherwise: bb3];
23-
+ _3 = const Option::<bool>::Some(true);
2423
+ _4 = const 1_isize;
2524
+ switchInt(const 1_isize) -> [1: bb1, otherwise: bb3];
2625
}
@@ -41,7 +40,8 @@
4140
}
4241

4342
bb4: {
44-
_1 = Add(move _2, const 0_i32);
43+
- _1 = Add(move _2, const 0_i32);
44+
+ _1 = const 42_i32;
4545
StorageDead(_2);
4646
StorageDead(_3);
4747
_0 = const ();

tests/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
StorageLive(_1);
1818
StorageLive(_2);
1919
StorageLive(_3);
20-
- _3 = Option::<bool>::Some(const true);
20+
_3 = Option::<bool>::Some(const true);
2121
- _4 = discriminant(_3);
2222
- switchInt(move _4) -> [1: bb1, otherwise: bb3];
23-
+ _3 = const Option::<bool>::Some(true);
2423
+ _4 = const 1_isize;
2524
+ switchInt(const 1_isize) -> [1: bb1, otherwise: bb3];
2625
}
@@ -41,7 +40,8 @@
4140
}
4241

4342
bb4: {
44-
_1 = Add(move _2, const 0_i32);
43+
- _1 = Add(move _2, const 0_i32);
44+
+ _1 = const 42_i32;
4545
StorageDead(_2);
4646
StorageDead(_3);
4747
_0 = const ();

tests/mir-opt/dataflow-const-prop/enum.multiple.DataflowConstProp.diff renamed to tests/mir-opt/const_prop/enum.multiple.ConstProp.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `multiple` before DataflowConstProp
2-
+ // MIR for `multiple` after DataflowConstProp
1+
- // MIR for `multiple` before ConstProp
2+
+ // MIR for `multiple` after ConstProp
33

44
fn multiple(_1: bool, _2: u8) -> () {
55
debug x => _1;

tests/mir-opt/dataflow-const-prop/enum.mutate_discriminant.DataflowConstProp.diff renamed to tests/mir-opt/const_prop/enum.mutate_discriminant.ConstProp.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `mutate_discriminant` before DataflowConstProp
2-
+ // MIR for `mutate_discriminant` after DataflowConstProp
1+
- // MIR for `mutate_discriminant` before ConstProp
2+
+ // MIR for `mutate_discriminant` after ConstProp
33

44
fn mutate_discriminant() -> u8 {
55
let mut _0: u8;

0 commit comments

Comments
 (0)