Skip to content

Commit f229fe6

Browse files
committed
Replace ConstProp by DataflowConstProp.
1 parent ffc48e3 commit f229fe6

File tree

165 files changed

+264
-2598
lines changed

Some content is hidden

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

165 files changed

+264
-2598
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

+13-553
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
@@ -24,11 +24,11 @@ use crate::MirPass;
2424
const BLOCK_LIMIT: usize = 100;
2525
const PLACE_LIMIT: usize = 100;
2626

27-
pub struct DataflowConstProp;
27+
pub struct ConstProp;
2828

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

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

compiler/rustc_mir_transform/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
549549
// destroy the SSA property. It should still happen before const-propagation, so the
550550
// latter pass will leverage the created opportunities.
551551
&separate_const_switch::SeparateConstSwitch,
552-
&const_prop::ConstProp,
553-
&dataflow_const_prop::DataflowConstProp,
552+
&dataflow_const_prop::ConstProp,
554553
//
555554
// Const-prop runs unconditionally, but doesn't mutate the MIR at mir-opt-level=0.
556555
&const_debuginfo::ConstDebugInfo,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
bb1: {
3030
- _1 = _2[_3];
31-
+ _1 = const 2_u32;
31+
+ _1 = _2[2 of 3];
3232
StorageDead(_3);
3333
StorageDead(_2);
3434
_0 = const ();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
bb1: {
3030
- _1 = _2[_3];
31-
+ _1 = const 2_u32;
31+
+ _1 = _2[2 of 3];
3232
StorageDead(_3);
3333
StorageDead(_2);
3434
_0 = const ();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
bb1: {
3030
- _1 = _2[_3];
31-
+ _1 = const 2_u32;
31+
+ _1 = _2[2 of 3];
3232
StorageDead(_3);
3333
StorageDead(_2);
3434
_0 = const ();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
bb1: {
3030
- _1 = _2[_3];
31-
+ _1 = const 2_u32;
31+
+ _1 = _2[2 of 3];
3232
StorageDead(_3);
3333
StorageDead(_2);
3434
_0 = const ();

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434
StorageLive(_5);
3535
StorageLive(_6);
3636
_6 = const 3_usize;
37-
_7 = Len((*_1));
37+
- _7 = Len((*_1));
3838
- _8 = Lt(_6, _7);
3939
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable];
40-
+ _8 = Lt(const 3_usize, _7);
41-
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 3_usize) -> [success: bb1, unwind unreachable];
40+
+ _7 = const 3_usize;
41+
+ _8 = const false;
42+
+ assert(const false, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 3_usize) -> [success: bb1, unwind unreachable];
4243
}
4344

4445
bb1: {

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434
StorageLive(_5);
3535
StorageLive(_6);
3636
_6 = const 3_usize;
37-
_7 = Len((*_1));
37+
- _7 = Len((*_1));
3838
- _8 = Lt(_6, _7);
3939
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind continue];
40-
+ _8 = Lt(const 3_usize, _7);
41-
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 3_usize) -> [success: bb1, unwind continue];
40+
+ _7 = const 3_usize;
41+
+ _8 = const false;
42+
+ assert(const false, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 3_usize) -> [success: bb1, unwind continue];
4243
}
4344

4445
bb1: {

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434
StorageLive(_5);
3535
StorageLive(_6);
3636
_6 = const 3_usize;
37-
_7 = Len((*_1));
37+
- _7 = Len((*_1));
3838
- _8 = Lt(_6, _7);
3939
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable];
40-
+ _8 = Lt(const 3_usize, _7);
41-
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 3_usize) -> [success: bb1, unwind unreachable];
40+
+ _7 = const 3_usize;
41+
+ _8 = const false;
42+
+ assert(const false, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 3_usize) -> [success: bb1, unwind unreachable];
4243
}
4344

4445
bb1: {

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434
StorageLive(_5);
3535
StorageLive(_6);
3636
_6 = const 3_usize;
37-
_7 = Len((*_1));
37+
- _7 = Len((*_1));
3838
- _8 = Lt(_6, _7);
3939
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind continue];
40-
+ _8 = Lt(const 3_usize, _7);
41-
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 3_usize) -> [success: bb1, unwind continue];
40+
+ _7 = const 3_usize;
41+
+ _8 = const false;
42+
+ assert(const false, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 3_usize) -> [success: bb1, unwind continue];
4243
}
4344

4445
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;

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// unit-test: DataflowConstProp
1+
// unit-test: ConstProp
22

33
#![feature(custom_mir, core_intrinsics, rustc_attrs)]
44

@@ -9,7 +9,7 @@ enum E {
99
V2(i32)
1010
}
1111

12-
// EMIT_MIR enum.simple.DataflowConstProp.diff
12+
// EMIT_MIR enum.simple.ConstProp.diff
1313
fn simple() {
1414
let e = E::V1(0);
1515
let x = match e { E::V1(x) => x, E::V2(x) => x };
@@ -19,7 +19,7 @@ fn simple() {
1919
#[rustc_nonnull_optimization_guaranteed]
2020
struct NonZeroUsize(usize);
2121

22-
// EMIT_MIR enum.mutate_discriminant.DataflowConstProp.diff
22+
// EMIT_MIR enum.mutate_discriminant.ConstProp.diff
2323
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
2424
fn mutate_discriminant() -> u8 {
2525
mir!(
@@ -46,7 +46,7 @@ fn mutate_discriminant() -> u8 {
4646
)
4747
}
4848

49-
// EMIT_MIR enum.multiple.DataflowConstProp.diff
49+
// EMIT_MIR enum.multiple.ConstProp.diff
5050
fn multiple(x: bool, i: u8) {
5151
let e = if x {
5252
Some(i)

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

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

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

tests/mir-opt/dataflow-const-prop/if.main.DataflowConstProp.diff renamed to tests/mir-opt/const_prop/if.main.ConstProp.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/if.rs renamed to tests/mir-opt/const_prop/if.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// unit-test: DataflowConstProp
1+
// unit-test: ConstProp
22

3-
// EMIT_MIR if.main.DataflowConstProp.diff
3+
// EMIT_MIR if.main.ConstProp.diff
44
fn main() {
55
let a = 1;
66
let b = if a == 1 { 2 } else { 3 };

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
- _3 = CheckedAdd(_2, const 1_u8);
1818
- assert(!move (_3.1: bool), "attempt to compute `{} + {}`, which would overflow", move _2, const 1_u8) -> [success: bb1, unwind unreachable];
1919
+ _2 = const 2_u8;
20-
+ _3 = const (3_u8, false);
20+
+ _3 = CheckedAdd(const 2_u8, const 1_u8);
2121
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_u8, const 1_u8) -> [success: bb1, unwind unreachable];
2222
}
2323

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
- _3 = CheckedAdd(_2, const 1_u8);
1818
- assert(!move (_3.1: bool), "attempt to compute `{} + {}`, which would overflow", move _2, const 1_u8) -> [success: bb1, unwind continue];
1919
+ _2 = const 2_u8;
20-
+ _3 = const (3_u8, false);
20+
+ _3 = CheckedAdd(const 2_u8, const 1_u8);
2121
+ assert(!const false, "attempt to compute `{} + {}`, which would overflow", const 2_u8, const 1_u8) -> [success: bb1, unwind continue];
2222
}
2323

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
_3 = const 1_u8;
2323
- _4 = CheckedAdd(_2, _3);
2424
- assert(!move (_4.1: bool), "attempt to compute `{} + {}`, which would overflow", _2, _3) -> [success: bb1, unwind unreachable];
25-
+ _4 = const (0_u8, true);
25+
+ _4 = CheckedAdd(const u8::MAX, const 1_u8);
2626
+ assert(!const true, "attempt to compute `{} + {}`, which would overflow", const u8::MAX, const 1_u8) -> [success: bb1, unwind unreachable];
2727
}
2828

0 commit comments

Comments
 (0)