Skip to content

Commit 96205a4

Browse files
committed
Replace legacy ConstProp by GVN.
1 parent 3c5b57c commit 96205a4

File tree

199 files changed

+1208
-1785
lines changed

Some content is hidden

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

199 files changed

+1208
-1785
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

+9-505
Large diffs are not rendered by default.

compiler/rustc_mir_transform/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
553553
&separate_const_switch::SeparateConstSwitch,
554554
&gvn::GVN,
555555
&simplify::SimplifyLocals::AfterGVN,
556-
&const_prop::ConstProp,
557556
&dataflow_const_prop::DataflowConstProp,
558557
//
559558
// Const-prop runs unconditionally, but doesn't mutate the MIR at mir-opt-level=0.

tests/codegen/inherit_overflow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Zmir-enable-passes=+Inline,+ConstProp --crate-type lib
1+
// compile-flags: -Zmir-enable-passes=+Inline,+GVN --crate-type lib
22
// revisions: ASSERT NOASSERT
33
//[ASSERT] compile-flags: -Coverflow-checks=on
44
//[NOASSERT] compile-flags: -Coverflow-checks=off

tests/mir-opt/const_allocation.main.ConstProp.after.32bit.mir tests/mir-opt/const_allocation.main.GVN.after.32bit.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// MIR for `main` after ConstProp
1+
// MIR for `main` after GVN
22

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

tests/mir-opt/const_allocation.main.ConstProp.after.64bit.mir tests/mir-opt/const_allocation.main.GVN.after.64bit.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// MIR for `main` after ConstProp
1+
// MIR for `main` after GVN
22

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

tests/mir-opt/const_allocation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// unit-test: ConstProp
1+
// unit-test: GVN
22
// ignore-endian-big
33
// EMIT_MIR_FOR_EACH_BIT_WIDTH
44
static FOO: &[(Option<i32>, &[&str])] =
55
&[(None, &[]), (None, &["foo", "bar"]), (Some(42), &["meh", "mop", "möp"])];
66

7-
// EMIT_MIR const_allocation.main.ConstProp.after.mir
7+
// EMIT_MIR const_allocation.main.GVN.after.mir
88
fn main() {
99
FOO;
1010
}

tests/mir-opt/const_allocation2.main.ConstProp.after.32bit.mir tests/mir-opt/const_allocation2.main.GVN.after.32bit.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// MIR for `main` after ConstProp
1+
// MIR for `main` after GVN
22

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

tests/mir-opt/const_allocation2.main.ConstProp.after.64bit.mir tests/mir-opt/const_allocation2.main.GVN.after.64bit.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// MIR for `main` after ConstProp
1+
// MIR for `main` after GVN
22

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

tests/mir-opt/const_allocation2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// unit-test: ConstProp
1+
// unit-test: GVN
22
// ignore-endian-big
33
// EMIT_MIR_FOR_EACH_BIT_WIDTH
4-
// EMIT_MIR const_allocation2.main.ConstProp.after.mir
4+
// EMIT_MIR const_allocation2.main.GVN.after.mir
55
fn main() {
66
FOO;
77
}

tests/mir-opt/const_allocation3.main.ConstProp.after.32bit.mir tests/mir-opt/const_allocation3.main.GVN.after.32bit.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// MIR for `main` after ConstProp
1+
// MIR for `main` after GVN
22

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

tests/mir-opt/const_allocation3.main.ConstProp.after.64bit.mir tests/mir-opt/const_allocation3.main.GVN.after.64bit.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// MIR for `main` after ConstProp
1+
// MIR for `main` after GVN
22

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

tests/mir-opt/const_allocation3.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// unit-test: ConstProp
1+
// unit-test: GVN
22
// ignore-endian-big
33
// EMIT_MIR_FOR_EACH_BIT_WIDTH
4-
// EMIT_MIR const_allocation3.main.ConstProp.after.mir
4+
// EMIT_MIR const_allocation3.main.GVN.after.mir
55
fn main() {
66
FOO;
77
}

tests/mir-opt/const_prop/address_of_pair.fn0.ConstProp.diff tests/mir-opt/const_prop/address_of_pair.fn0.GVN.diff

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `fn0` before ConstProp
2-
+ // MIR for `fn0` after ConstProp
1+
- // MIR for `fn0` before GVN
2+
+ // MIR for `fn0` after GVN
33

44
fn fn0() -> bool {
55
let mut _0: bool;
@@ -23,24 +23,32 @@
2323

2424
bb0: {
2525
StorageLive(_2);
26-
_2 = (const 1_i32, const false);
26+
- _2 = (const 1_i32, const false);
27+
+ _2 = const (1_i32, false);
2728
StorageLive(_3);
2829
_3 = &raw mut (_2.1: bool);
29-
_2 = (const 1_i32, const false);
30+
- _2 = (const 1_i32, const false);
31+
+ _2 = const (1_i32, false);
3032
StorageLive(_4);
3133
(*_3) = const true;
3234
_4 = const ();
3335
StorageDead(_4);
34-
StorageLive(_5);
36+
- StorageLive(_5);
37+
+ nop;
3538
StorageLive(_6);
3639
_6 = (_2.1: bool);
3740
_5 = Not(move _6);
3841
StorageDead(_6);
3942
_0 = _5;
40-
StorageDead(_5);
43+
- StorageDead(_5);
44+
+ nop;
4145
StorageDead(_3);
4246
StorageDead(_2);
4347
return;
4448
}
49+
+ }
50+
+
51+
+ alloc7 (size: 8, align: 4) {
52+
+ 01 00 00 00 00 __ __ __ │ .....░░░
4553
}
4654

tests/mir-opt/const_prop/address_of_pair.rs

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

3-
// EMIT_MIR address_of_pair.fn0.ConstProp.diff
3+
// EMIT_MIR address_of_pair.fn0.GVN.diff
44
pub fn fn0() -> bool {
55
let mut pair = (1, false);
66
let ptr = core::ptr::addr_of_mut!(pair.1);

tests/mir-opt/const_prop/aggregate.foo.ConstProp.panic-abort.diff tests/mir-opt/const_prop/aggregate.foo.GVN.panic-abort.diff

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `foo` before ConstProp
2-
+ // MIR for `foo` after ConstProp
1+
- // MIR for `foo` before GVN
2+
+ // MIR for `foo` after GVN
33

44
fn foo(_1: u8) -> () {
55
debug x => _1;
@@ -25,25 +25,23 @@
2525
StorageLive(_4);
2626
StorageLive(_5);
2727
_5 = _1;
28-
_4 = (const 0_i32, move _5);
28+
- _4 = (const 0_i32, move _5);
29+
+ _4 = (const 0_i32, _1);
2930
StorageDead(_5);
30-
- _3 = (_4.0: i32);
31-
- _2 = Add(move _3, const 1_i32);
32-
+ _3 = const 0_i32;
33-
+ _2 = const 1_i32;
31+
_3 = (_4.0: i32);
32+
_2 = Add(move _3, const 1_i32);
3433
StorageDead(_3);
3534
StorageDead(_4);
3635
StorageLive(_6);
3736
StorageLive(_7);
3837
StorageLive(_8);
3938
StorageLive(_9);
4039
_9 = _1;
41-
_8 = (move _9, const 1_i32);
40+
- _8 = (move _9, const 1_i32);
41+
+ _8 = (_1, const 1_i32);
4242
StorageDead(_9);
43-
- _7 = (_8.1: i32);
44-
- _6 = Add(move _7, const 2_i32);
45-
+ _7 = const 1_i32;
46-
+ _6 = const 3_i32;
43+
_7 = (_8.1: i32);
44+
_6 = Add(move _7, const 2_i32);
4745
StorageDead(_7);
4846
StorageDead(_8);
4947
_0 = const ();

tests/mir-opt/const_prop/aggregate.foo.ConstProp.panic-unwind.diff tests/mir-opt/const_prop/aggregate.foo.GVN.panic-unwind.diff

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `foo` before ConstProp
2-
+ // MIR for `foo` after ConstProp
1+
- // MIR for `foo` before GVN
2+
+ // MIR for `foo` after GVN
33

44
fn foo(_1: u8) -> () {
55
debug x => _1;
@@ -25,25 +25,23 @@
2525
StorageLive(_4);
2626
StorageLive(_5);
2727
_5 = _1;
28-
_4 = (const 0_i32, move _5);
28+
- _4 = (const 0_i32, move _5);
29+
+ _4 = (const 0_i32, _1);
2930
StorageDead(_5);
30-
- _3 = (_4.0: i32);
31-
- _2 = Add(move _3, const 1_i32);
32-
+ _3 = const 0_i32;
33-
+ _2 = const 1_i32;
31+
_3 = (_4.0: i32);
32+
_2 = Add(move _3, const 1_i32);
3433
StorageDead(_3);
3534
StorageDead(_4);
3635
StorageLive(_6);
3736
StorageLive(_7);
3837
StorageLive(_8);
3938
StorageLive(_9);
4039
_9 = _1;
41-
_8 = (move _9, const 1_i32);
40+
- _8 = (move _9, const 1_i32);
41+
+ _8 = (_1, const 1_i32);
4242
StorageDead(_9);
43-
- _7 = (_8.1: i32);
44-
- _6 = Add(move _7, const 2_i32);
45-
+ _7 = const 1_i32;
46-
+ _6 = const 3_i32;
43+
_7 = (_8.1: i32);
44+
_6 = Add(move _7, const 2_i32);
4745
StorageDead(_7);
4846
StorageDead(_8);
4947
_0 = const ();

tests/mir-opt/const_prop/aggregate.foo.PreCodegen.after.panic-abort.mir

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ fn foo(_1: u8) -> () {
2424
StorageLive(_4);
2525
StorageLive(_5);
2626
_5 = _1;
27-
_4 = (const 0_i32, move _5);
27+
_4 = (const 0_i32, _1);
2828
StorageDead(_5);
29-
_3 = const 0_i32;
30-
_2 = const 1_i32;
29+
_3 = (_4.0: i32);
30+
_2 = Add(move _3, const 1_i32);
3131
StorageDead(_3);
3232
StorageDead(_4);
3333
StorageLive(_6);
3434
StorageLive(_7);
3535
StorageLive(_8);
3636
StorageLive(_9);
3737
_9 = _1;
38-
_8 = (move _9, const 1_i32);
38+
_8 = (_1, const 1_i32);
3939
StorageDead(_9);
40-
_7 = const 1_i32;
41-
_6 = const 3_i32;
40+
_7 = (_8.1: i32);
41+
_6 = Add(move _7, const 2_i32);
4242
StorageDead(_7);
4343
StorageDead(_8);
4444
_0 = const ();

tests/mir-opt/const_prop/aggregate.foo.PreCodegen.after.panic-unwind.mir

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ fn foo(_1: u8) -> () {
2424
StorageLive(_4);
2525
StorageLive(_5);
2626
_5 = _1;
27-
_4 = (const 0_i32, move _5);
27+
_4 = (const 0_i32, _1);
2828
StorageDead(_5);
29-
_3 = const 0_i32;
30-
_2 = const 1_i32;
29+
_3 = (_4.0: i32);
30+
_2 = Add(move _3, const 1_i32);
3131
StorageDead(_3);
3232
StorageDead(_4);
3333
StorageLive(_6);
3434
StorageLive(_7);
3535
StorageLive(_8);
3636
StorageLive(_9);
3737
_9 = _1;
38-
_8 = (move _9, const 1_i32);
38+
_8 = (_1, const 1_i32);
3939
StorageDead(_9);
40-
_7 = const 1_i32;
41-
_6 = const 3_i32;
40+
_7 = (_8.1: i32);
41+
_6 = Add(move _7, const 2_i32);
4242
StorageDead(_7);
4343
StorageDead(_8);
4444
_0 = const ();

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

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

44
fn main() -> () {
55
let mut _0: ();
@@ -13,7 +13,8 @@
1313
}
1414

1515
bb0: {
16-
StorageLive(_1);
16+
- StorageLive(_1);
17+
+ nop;
1718
StorageLive(_2);
1819
StorageLive(_3);
1920
_3 = (const 0_i32, const 1_u8, const 2_i32);
@@ -35,7 +36,8 @@
3536
StorageDead(_5);
3637
StorageDead(_4);
3738
_0 = const ();
38-
StorageDead(_1);
39+
- StorageDead(_1);
40+
+ nop;
3941
return;
4042
}
4143
}

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

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

44
fn main() -> () {
55
let mut _0: ();
@@ -13,7 +13,8 @@
1313
}
1414

1515
bb0: {
16-
StorageLive(_1);
16+
- StorageLive(_1);
17+
+ nop;
1718
StorageLive(_2);
1819
StorageLive(_3);
1920
_3 = (const 0_i32, const 1_u8, const 2_i32);
@@ -35,7 +36,8 @@
3536
StorageDead(_5);
3637
StorageDead(_4);
3738
_0 = const ();
38-
StorageDead(_1);
39+
- StorageDead(_1);
40+
+ nop;
3941
return;
4042
}
4143
}

tests/mir-opt/const_prop/aggregate.main.PreCodegen.after.panic-abort.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() -> () {
1212
}
1313

1414
bb0: {
15-
StorageLive(_1);
15+
nop;
1616
StorageLive(_2);
1717
StorageLive(_3);
1818
_3 = (const 0_i32, const 1_u8, const 2_i32);
@@ -30,7 +30,7 @@ fn main() -> () {
3030
StorageDead(_5);
3131
StorageDead(_4);
3232
_0 = const ();
33-
StorageDead(_1);
33+
nop;
3434
return;
3535
}
3636
}

tests/mir-opt/const_prop/aggregate.main.PreCodegen.after.panic-unwind.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() -> () {
1212
}
1313

1414
bb0: {
15-
StorageLive(_1);
15+
nop;
1616
StorageLive(_2);
1717
StorageLive(_3);
1818
_3 = (const 0_i32, const 1_u8, const 2_i32);
@@ -30,7 +30,7 @@ fn main() -> () {
3030
StorageDead(_5);
3131
StorageDead(_4);
3232
_0 = const ();
33-
StorageDead(_1);
33+
nop;
3434
return;
3535
}
3636
}

tests/mir-opt/const_prop/aggregate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
2-
// unit-test: ConstProp
2+
// unit-test: GVN
33
// compile-flags: -O
44

5-
// EMIT_MIR aggregate.main.ConstProp.diff
5+
// EMIT_MIR aggregate.main.GVN.diff
66
// EMIT_MIR aggregate.main.PreCodegen.after.mir
77
fn main() {
88
let x = (0, 1, 2).1 + 0;
99
foo(x);
1010
}
1111

12-
// EMIT_MIR aggregate.foo.ConstProp.diff
12+
// EMIT_MIR aggregate.foo.GVN.diff
1313
// EMIT_MIR aggregate.foo.PreCodegen.after.mir
1414
fn foo(x: u8) {
1515
// Verify that we still propagate if part of the aggregate is not known.

0 commit comments

Comments
 (0)