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

Lines changed: 13 additions & 541 deletions
Large diffs are not rendered by default.

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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);

0 commit comments

Comments
 (0)