Skip to content

Commit 30a03fc

Browse files
committed
Replace legacy ConstProp by GVN.
1 parent fee4e3e commit 30a03fc

File tree

190 files changed

+1360
-1713
lines changed

Some content is hidden

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

190 files changed

+1360
-1713
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

+11-515
Large diffs are not rendered by default.

compiler/rustc_mir_transform/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
589589
&separate_const_switch::SeparateConstSwitch,
590590
&gvn::GVN,
591591
&simplify::SimplifyLocals::AfterGVN,
592-
&const_prop::ConstProp,
593592
&dataflow_const_prop::DataflowConstProp,
594593
&const_debuginfo::ConstDebugInfo,
595594
&o1(simplify_branches::SimplifyConstCondition::AfterConstProp),

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 renamed to tests/mir-opt/const_allocation.main.GVN.after.32bit.mir

+3-3
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: ();
@@ -7,10 +7,10 @@ fn main() -> () {
77

88
bb0: {
99
StorageLive(_1);
10-
StorageLive(_2);
10+
nop;
1111
_2 = const {ALLOC9: &&[(Option<i32>, &[&str])]};
1212
_1 = (*_2);
13-
StorageDead(_2);
13+
nop;
1414
StorageDead(_1);
1515
_0 = const ();
1616
return;

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

+3-3
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: ();
@@ -7,10 +7,10 @@ fn main() -> () {
77

88
bb0: {
99
StorageLive(_1);
10-
StorageLive(_2);
10+
nop;
1111
_2 = const {ALLOC9: &&[(Option<i32>, &[&str])]};
1212
_1 = (*_2);
13-
StorageDead(_2);
13+
nop;
1414
StorageDead(_1);
1515
_0 = const ();
1616
return;

tests/mir-opt/const_allocation.rs

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

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

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

+3-3
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: ();
@@ -7,10 +7,10 @@ fn main() -> () {
77

88
bb0: {
99
StorageLive(_1);
10-
StorageLive(_2);
10+
nop;
1111
_2 = const {ALLOC9: &&[(Option<i32>, &[&u8])]};
1212
_1 = (*_2);
13-
StorageDead(_2);
13+
nop;
1414
StorageDead(_1);
1515
_0 = const ();
1616
return;

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

+3-3
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: ();
@@ -7,10 +7,10 @@ fn main() -> () {
77

88
bb0: {
99
StorageLive(_1);
10-
StorageLive(_2);
10+
nop;
1111
_2 = const {ALLOC9: &&[(Option<i32>, &[&u8])]};
1212
_1 = (*_2);
13-
StorageDead(_2);
13+
nop;
1414
StorageDead(_1);
1515
_0 = const ();
1616
return;

tests/mir-opt/const_allocation2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// skip-filecheck
2-
// unit-test: ConstProp
2+
// unit-test: GVN
33
// ignore-endian-big
44
// EMIT_MIR_FOR_EACH_BIT_WIDTH
5-
// EMIT_MIR const_allocation2.main.ConstProp.after.mir
5+
// EMIT_MIR const_allocation2.main.GVN.after.mir
66
fn main() {
77
FOO;
88
}

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

+3-3
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: ();
@@ -7,10 +7,10 @@ fn main() -> () {
77

88
bb0: {
99
StorageLive(_1);
10-
StorageLive(_2);
10+
nop;
1111
_2 = const {ALLOC4: &&Packed};
1212
_1 = (*_2);
13-
StorageDead(_2);
13+
nop;
1414
StorageDead(_1);
1515
_0 = const ();
1616
return;

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

+3-3
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: ();
@@ -7,10 +7,10 @@ fn main() -> () {
77

88
bb0: {
99
StorageLive(_1);
10-
StorageLive(_2);
10+
nop;
1111
_2 = const {ALLOC2: &&Packed};
1212
_1 = (*_2);
13-
StorageDead(_2);
13+
nop;
1414
StorageDead(_1);
1515
_0 = const ();
1616
return;

tests/mir-opt/const_allocation3.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// skip-filecheck
2-
// unit-test: ConstProp
2+
// unit-test: GVN
33
// ignore-endian-big
44
// EMIT_MIR_FOR_EACH_BIT_WIDTH
5-
// EMIT_MIR const_allocation3.main.ConstProp.after.mir
5+
// EMIT_MIR const_allocation3.main.GVN.after.mir
66
fn main() {
77
FOO;
88
}

tests/mir-opt/const_debuginfo.main.ConstDebugInfo.diff

+15-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
debug f => _10;
3535
let _11: std::option::Option<u16>;
3636
scope 7 {
37-
debug o => _11;
37+
- debug o => _11;
38+
+ debug o => const Option::<u16>::Some(99_u16);
3839
let _12: Point;
3940
scope 8 {
4041
- debug p => _12;
@@ -54,11 +55,11 @@
5455
}
5556

5657
bb0: {
57-
StorageLive(_1);
58+
nop;
5859
_1 = const 1_u8;
59-
StorageLive(_2);
60+
nop;
6061
_2 = const 2_u8;
61-
StorageLive(_3);
62+
nop;
6263
_3 = const 3_u8;
6364
StorageLive(_4);
6465
StorageLive(_5);
@@ -79,27 +80,27 @@
7980
StorageLive(_10);
8081
_10 = (const true, const false, const 123_u32);
8182
StorageLive(_11);
82-
_11 = Option::<u16>::Some(const 99_u16);
83+
_11 = const Option::<u16>::Some(99_u16);
8384
StorageLive(_12);
8485
_12 = const Point {{ x: 32_u32, y: 32_u32 }};
8586
StorageLive(_13);
86-
StorageLive(_14);
87+
nop;
8788
_14 = const 32_u32;
8889
StorageLive(_15);
8990
_15 = const 32_u32;
9091
_13 = const 64_u32;
9192
StorageDead(_15);
92-
StorageDead(_14);
93+
nop;
9394
_0 = const ();
9495
StorageDead(_13);
9596
StorageDead(_12);
9697
StorageDead(_11);
9798
StorageDead(_10);
9899
StorageDead(_9);
99100
StorageDead(_4);
100-
StorageDead(_3);
101-
StorageDead(_2);
102-
StorageDead(_1);
101+
nop;
102+
nop;
103+
nop;
103104
return;
104105
}
105106
}
@@ -108,3 +109,7 @@
108109
20 00 00 00 20 00 00 00 │ ... ...
109110
}
110111

112+
ALLOC1 (size: 4, align: 2) {
113+
01 00 63 00 │ ..c.
114+
}
115+

tests/mir-opt/const_debuginfo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// unit-test: ConstDebugInfo
2-
// compile-flags: -C overflow-checks=no -Zmir-enable-passes=+ConstProp
2+
// compile-flags: -C overflow-checks=no -Zmir-enable-passes=+GVN
33

44
struct Point {
55
x: u32,
@@ -15,7 +15,7 @@ fn main() {
1515
// CHECK: debug sum => const 6_u8;
1616
// CHECK: debug s => const "hello, world!";
1717
// CHECK: debug f => {{_.*}};
18-
// CHECK: debug o => {{_.*}};
18+
// CHECK: debug o => const Option::<u16>::Some(99_u16);
1919
// CHECK: debug p => const Point
2020
// CHECK: debug a => const 64_u32;
2121
let x = 1u8;

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

+18-8
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,34 @@
2323

2424
bb0: {
2525
StorageLive(_2);
26-
_2 = (const 1_i32, const false);
27-
StorageLive(_3);
26+
- _2 = (const 1_i32, const false);
27+
- StorageLive(_3);
28+
+ _2 = const (1_i32, false);
29+
+ nop;
2830
_3 = &raw mut (_2.1: bool);
29-
_2 = (const 1_i32, const false);
31+
- _2 = (const 1_i32, const false);
32+
+ _2 = const (1_i32, false);
3033
StorageLive(_4);
3134
(*_3) = const true;
3235
_4 = const ();
3336
StorageDead(_4);
34-
StorageLive(_5);
37+
- StorageLive(_5);
38+
+ nop;
3539
StorageLive(_6);
3640
_6 = (_2.1: bool);
3741
_5 = Not(move _6);
3842
StorageDead(_6);
3943
_0 = _5;
40-
StorageDead(_5);
41-
StorageDead(_3);
44+
- StorageDead(_5);
45+
- StorageDead(_3);
46+
+ nop;
47+
+ nop;
4248
StorageDead(_2);
4349
return;
4450
}
51+
+ }
52+
+
53+
+ ALLOC0 (size: 8, align: 4) {
54+
+ 01 00 00 00 00 __ __ __ │ .....░░░
4555
}
4656

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
// CHECK-LABEL: fn fn0(
66
// CHECK: debug pair => [[pair:_.*]];

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

+6-4
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,7 +25,8 @@
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);
3031
- _3 = (_4.0: i32);
3132
- _2 = Add(move _3, const 1_i32);
@@ -38,7 +39,8 @@
3839
StorageLive(_8);
3940
StorageLive(_9);
4041
_9 = _1;
41-
_8 = (move _9, const 1_i32);
42+
- _8 = (move _9, const 1_i32);
43+
+ _8 = (_1, const 1_i32);
4244
StorageDead(_9);
4345
- _7 = (_8.1: i32);
4446
- _6 = Add(move _7, const 2_i32);

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

+6-4
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,7 +25,8 @@
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);
3031
- _3 = (_4.0: i32);
3132
- _2 = Add(move _3, const 1_i32);
@@ -38,7 +39,8 @@
3839
StorageLive(_8);
3940
StorageLive(_9);
4041
_9 = _1;
41-
_8 = (move _9, const 1_i32);
42+
- _8 = (move _9, const 1_i32);
43+
+ _8 = (_1, const 1_i32);
4244
StorageDead(_9);
4345
- _7 = (_8.1: i32);
4446
- _6 = Add(move _7, const 2_i32);

tests/mir-opt/const_prop/aggregate.main.ConstProp.panic-abort.diff renamed to 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
}

0 commit comments

Comments
 (0)