Skip to content

Commit

Permalink
Replace legacy ConstProp by GVN.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Sep 20, 2023
1 parent 0741259 commit 358e9a7
Show file tree
Hide file tree
Showing 199 changed files with 1,236 additions and 1,790 deletions.
514 changes: 9 additions & 505 deletions compiler/rustc_mir_transform/src/const_prop.rs

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
&separate_const_switch::SeparateConstSwitch,
&gvn::GVN,
&simplify::SimplifyLocals::AfterGVN,
&const_prop::ConstProp,
&dataflow_const_prop::DataflowConstProp,
//
// Const-prop runs unconditionally, but doesn't mutate the MIR at mir-opt-level=0.
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/inherit_overflow.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: -Zmir-enable-passes=+Inline,+ConstProp --crate-type lib
// compile-flags: -Zmir-enable-passes=+Inline,+GVN --crate-type lib
// revisions: ASSERT NOASSERT
//[ASSERT] compile-flags: -Coverflow-checks=on
//[NOASSERT] compile-flags: -Coverflow-checks=off
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `main` after ConstProp
// MIR for `main` after GVN

fn main() -> () {
let mut _0: ();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `main` after ConstProp
// MIR for `main` after GVN

fn main() -> () {
let mut _0: ();
Expand Down
4 changes: 2 additions & 2 deletions tests/mir-opt/const_allocation.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// unit-test: ConstProp
// unit-test: GVN
// ignore-endian-big
// EMIT_MIR_FOR_EACH_BIT_WIDTH
static FOO: &[(Option<i32>, &[&str])] =
&[(None, &[]), (None, &["foo", "bar"]), (Some(42), &["meh", "mop", "möp"])];

// EMIT_MIR const_allocation.main.ConstProp.after.mir
// EMIT_MIR const_allocation.main.GVN.after.mir
fn main() {
FOO;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `main` after ConstProp
// MIR for `main` after GVN

fn main() -> () {
let mut _0: ();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `main` after ConstProp
// MIR for `main` after GVN

fn main() -> () {
let mut _0: ();
Expand Down
4 changes: 2 additions & 2 deletions tests/mir-opt/const_allocation2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// unit-test: ConstProp
// unit-test: GVN
// ignore-endian-big
// EMIT_MIR_FOR_EACH_BIT_WIDTH
// EMIT_MIR const_allocation2.main.ConstProp.after.mir
// EMIT_MIR const_allocation2.main.GVN.after.mir
fn main() {
FOO;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `main` after ConstProp
// MIR for `main` after GVN

fn main() -> () {
let mut _0: ();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MIR for `main` after ConstProp
// MIR for `main` after GVN

fn main() -> () {
let mut _0: ();
Expand Down
4 changes: 2 additions & 2 deletions tests/mir-opt/const_allocation3.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// unit-test: ConstProp
// unit-test: GVN
// ignore-endian-big
// EMIT_MIR_FOR_EACH_BIT_WIDTH
// EMIT_MIR const_allocation3.main.ConstProp.after.mir
// EMIT_MIR const_allocation3.main.GVN.after.mir
fn main() {
FOO;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- // MIR for `fn0` before ConstProp
+ // MIR for `fn0` after ConstProp
- // MIR for `fn0` before GVN
+ // MIR for `fn0` after GVN

fn fn0() -> bool {
let mut _0: bool;
Expand All @@ -23,24 +23,32 @@

bb0: {
StorageLive(_2);
_2 = (const 1_i32, const false);
- _2 = (const 1_i32, const false);
+ _2 = const (1_i32, false);
StorageLive(_3);
_3 = &raw mut (_2.1: bool);
_2 = (const 1_i32, const false);
- _2 = (const 1_i32, const false);
+ _2 = const (1_i32, false);
StorageLive(_4);
(*_3) = const true;
_4 = const ();
StorageDead(_4);
StorageLive(_5);
- StorageLive(_5);
+ nop;
StorageLive(_6);
_6 = (_2.1: bool);
_5 = Not(move _6);
StorageDead(_6);
_0 = _5;
StorageDead(_5);
- StorageDead(_5);
+ nop;
StorageDead(_3);
StorageDead(_2);
return;
}
+ }
+
+ alloc7 (size: 8, align: 4) {
+ 01 00 00 00 00 __ __ __ │ .....░░░
}

4 changes: 2 additions & 2 deletions tests/mir-opt/const_prop/address_of_pair.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// unit-test: ConstProp
// unit-test: GVN

// EMIT_MIR address_of_pair.fn0.ConstProp.diff
// EMIT_MIR address_of_pair.fn0.GVN.diff
pub fn fn0() -> bool {
let mut pair = (1, false);
let ptr = core::ptr::addr_of_mut!(pair.1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- // MIR for `foo` before ConstProp
+ // MIR for `foo` after ConstProp
- // MIR for `foo` before GVN
+ // MIR for `foo` after GVN

fn foo(_1: u8) -> () {
debug x => _1;
Expand All @@ -25,25 +25,23 @@
StorageLive(_4);
StorageLive(_5);
_5 = _1;
_4 = (const 0_i32, move _5);
- _4 = (const 0_i32, move _5);
+ _4 = (const 0_i32, _1);
StorageDead(_5);
- _3 = (_4.0: i32);
- _2 = Add(move _3, const 1_i32);
+ _3 = const 0_i32;
+ _2 = const 1_i32;
_3 = (_4.0: i32);
_2 = Add(move _3, const 1_i32);
StorageDead(_3);
StorageDead(_4);
StorageLive(_6);
StorageLive(_7);
StorageLive(_8);
StorageLive(_9);
_9 = _1;
_8 = (move _9, const 1_i32);
- _8 = (move _9, const 1_i32);
+ _8 = (_1, const 1_i32);
StorageDead(_9);
- _7 = (_8.1: i32);
- _6 = Add(move _7, const 2_i32);
+ _7 = const 1_i32;
+ _6 = const 3_i32;
_7 = (_8.1: i32);
_6 = Add(move _7, const 2_i32);
StorageDead(_7);
StorageDead(_8);
_0 = const ();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- // MIR for `foo` before ConstProp
+ // MIR for `foo` after ConstProp
- // MIR for `foo` before GVN
+ // MIR for `foo` after GVN

fn foo(_1: u8) -> () {
debug x => _1;
Expand All @@ -25,25 +25,23 @@
StorageLive(_4);
StorageLive(_5);
_5 = _1;
_4 = (const 0_i32, move _5);
- _4 = (const 0_i32, move _5);
+ _4 = (const 0_i32, _1);
StorageDead(_5);
- _3 = (_4.0: i32);
- _2 = Add(move _3, const 1_i32);
+ _3 = const 0_i32;
+ _2 = const 1_i32;
_3 = (_4.0: i32);
_2 = Add(move _3, const 1_i32);
StorageDead(_3);
StorageDead(_4);
StorageLive(_6);
StorageLive(_7);
StorageLive(_8);
StorageLive(_9);
_9 = _1;
_8 = (move _9, const 1_i32);
- _8 = (move _9, const 1_i32);
+ _8 = (_1, const 1_i32);
StorageDead(_9);
- _7 = (_8.1: i32);
- _6 = Add(move _7, const 2_i32);
+ _7 = const 1_i32;
+ _6 = const 3_i32;
_7 = (_8.1: i32);
_6 = Add(move _7, const 2_i32);
StorageDead(_7);
StorageDead(_8);
_0 = const ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ fn foo(_1: u8) -> () {
StorageLive(_4);
StorageLive(_5);
_5 = _1;
_4 = (const 0_i32, move _5);
_4 = (const 0_i32, _1);
StorageDead(_5);
_3 = const 0_i32;
_2 = const 1_i32;
_3 = (_4.0: i32);
_2 = Add(move _3, const 1_i32);
StorageDead(_3);
StorageDead(_4);
StorageLive(_6);
StorageLive(_7);
StorageLive(_8);
StorageLive(_9);
_9 = _1;
_8 = (move _9, const 1_i32);
_8 = (_1, const 1_i32);
StorageDead(_9);
_7 = const 1_i32;
_6 = const 3_i32;
_7 = (_8.1: i32);
_6 = Add(move _7, const 2_i32);
StorageDead(_7);
StorageDead(_8);
_0 = const ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ fn foo(_1: u8) -> () {
StorageLive(_4);
StorageLive(_5);
_5 = _1;
_4 = (const 0_i32, move _5);
_4 = (const 0_i32, _1);
StorageDead(_5);
_3 = const 0_i32;
_2 = const 1_i32;
_3 = (_4.0: i32);
_2 = Add(move _3, const 1_i32);
StorageDead(_3);
StorageDead(_4);
StorageLive(_6);
StorageLive(_7);
StorageLive(_8);
StorageLive(_9);
_9 = _1;
_8 = (move _9, const 1_i32);
_8 = (_1, const 1_i32);
StorageDead(_9);
_7 = const 1_i32;
_6 = const 3_i32;
_7 = (_8.1: i32);
_6 = Add(move _7, const 2_i32);
StorageDead(_7);
StorageDead(_8);
_0 = const ();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- // MIR for `main` before ConstProp
+ // MIR for `main` after ConstProp
- // MIR for `main` before GVN
+ // MIR for `main` after GVN

fn main() -> () {
let mut _0: ();
Expand All @@ -13,12 +13,14 @@
}

bb0: {
StorageLive(_1);
- StorageLive(_1);
+ nop;
StorageLive(_2);
StorageLive(_3);
_3 = (const 0_i32, const 1_u8, const 2_i32);
- _3 = (const 0_i32, const 1_u8, const 2_i32);
- _2 = (_3.1: u8);
- _1 = Add(move _2, const 0_u8);
+ _3 = const (0_i32, 1_u8, 2_i32);
+ _2 = const 1_u8;
+ _1 = const 1_u8;
StorageDead(_2);
Expand All @@ -35,8 +37,13 @@
StorageDead(_5);
StorageDead(_4);
_0 = const ();
StorageDead(_1);
- StorageDead(_1);
+ nop;
return;
}
+ }
+
+ alloc6 (size: 12, align: 4) {
+ 00 00 00 00 01 __ __ __ 02 00 00 00 │ .....░░░....
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- // MIR for `main` before ConstProp
+ // MIR for `main` after ConstProp
- // MIR for `main` before GVN
+ // MIR for `main` after GVN

fn main() -> () {
let mut _0: ();
Expand All @@ -13,12 +13,14 @@
}

bb0: {
StorageLive(_1);
- StorageLive(_1);
+ nop;
StorageLive(_2);
StorageLive(_3);
_3 = (const 0_i32, const 1_u8, const 2_i32);
- _3 = (const 0_i32, const 1_u8, const 2_i32);
- _2 = (_3.1: u8);
- _1 = Add(move _2, const 0_u8);
+ _3 = const (0_i32, 1_u8, 2_i32);
+ _2 = const 1_u8;
+ _1 = const 1_u8;
StorageDead(_2);
Expand All @@ -35,8 +37,13 @@
StorageDead(_5);
StorageDead(_4);
_0 = const ();
StorageDead(_1);
- StorageDead(_1);
+ nop;
return;
}
+ }
+
+ alloc6 (size: 12, align: 4) {
+ 00 00 00 00 01 __ __ __ 02 00 00 00 │ .....░░░....
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ fn main() -> () {
}

bb0: {
StorageLive(_1);
nop;
StorageLive(_2);
StorageLive(_3);
_3 = (const 0_i32, const 1_u8, const 2_i32);
_3 = const (0_i32, 1_u8, 2_i32);
_2 = const 1_u8;
_1 = const 1_u8;
StorageDead(_2);
Expand All @@ -30,7 +30,11 @@ fn main() -> () {
StorageDead(_5);
StorageDead(_4);
_0 = const ();
StorageDead(_1);
nop;
return;
}
}

alloc6 (size: 12, align: 4) {
00 00 00 00 01 __ __ __ 02 00 00 00 │ .....░░░....
}
Loading

0 comments on commit 358e9a7

Please sign in to comment.