Skip to content

Commit 8fcb387

Browse files
committed
Enable GVN by default.
1 parent b6219c3 commit 8fcb387

File tree

46 files changed

+886
-1082
lines changed

Some content is hidden

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

46 files changed

+886
-1082
lines changed

compiler/rustc_mir_transform/src/gvn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub struct GVN;
7676

7777
impl<'tcx> MirPass<'tcx> for GVN {
7878
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
79-
sess.mir_opt_level() >= 4
79+
sess.mir_opt_level() >= 2
8080
}
8181

8282
#[instrument(level = "trace", skip(self, tcx, body))]

compiler/rustc_mir_transform/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,9 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
551551
// destroy the SSA property. It should still happen before const-propagation, so the
552552
// latter pass will leverage the created opportunities.
553553
&separate_const_switch::SeparateConstSwitch,
554-
&const_prop::ConstProp,
555554
&gvn::GVN,
556555
&simplify::SimplifyLocals::AfterGVN,
556+
&const_prop::ConstProp,
557557
&dataflow_const_prop::DataflowConstProp,
558558
//
559559
// Const-prop runs unconditionally, but doesn't mutate the MIR at mir-opt-level=0.

tests/codegen/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
// CHECK: @STATIC = {{.*}}, align 4
1010

1111
// This checks the constants from inline_enum_const
12-
// CHECK: @alloc_af1f8e8e6f4b341431a1d405e652df2d = {{.*}}, align 2
12+
// CHECK: @0 = {{.*}}, align 2
1313

1414
// This checks the constants from {low,high}_align_const, they share the same
1515
// constant, but the alignment differs, so the higher one should be used
16-
// CHECK: [[LOW_HIGH:@alloc_[a-f0-9]+]] = {{.*}}, align 4
16+
// CHECK: [[LOW_HIGH:@[a-f0-9]+]] = {{.*}}, align 4
1717

1818
#[derive(Copy, Clone)]
1919
// repr(i16) is required for the {low,high}_align_const test

tests/codegen/issues/issue-105386-ub-in-debuginfo.rs

-2
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,3 @@ pub fn outer_function(x: S, y: S) -> usize {
1919
// CHECK-NOT: [[ptr_tmp:%.*]] = getelementptr inbounds %"{closure@{{.*.rs}}:9:23: 9:25}", ptr [[spill]]
2020
// CHECK-NOT: [[load:%.*]] = load ptr, ptr
2121
// CHECK: call void @llvm.lifetime.start{{.*}}({{.*}}, ptr [[spill]])
22-
// CHECK: [[inner:%.*]] = getelementptr inbounds %"{{.*}}", ptr [[spill]]
23-
// CHECK: call void @llvm.memcpy{{.*}}(ptr {{align .*}} [[inner]], ptr {{align .*}} %x

tests/codegen/slice-ref-equality.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -44,48 +44,48 @@ pub fn is_zero_array(data: &[u8; 4]) -> bool {
4444
// equality for non-byte types also just emit a `bcmp`, not a loop.
4545

4646
// CHECK-LABEL: @eq_slice_of_nested_u8(
47-
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
48-
// CHECK-SAME: [[USIZE]] noundef %3
47+
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %x.1
48+
// CHECK-SAME: [[USIZE]] noundef %y.1
4949
#[no_mangle]
5050
fn eq_slice_of_nested_u8(x: &[[u8; 3]], y: &[[u8; 3]]) -> bool {
51-
// CHECK: icmp eq [[USIZE]] %1, %3
52-
// CHECK: %[[BYTES:.+]] = mul nsw [[USIZE]] %1, 3
51+
// CHECK: icmp eq [[USIZE]] %x.1, %y.1
52+
// CHECK: %[[BYTES:.+]] = mul nsw [[USIZE]] %x.1, 3
5353
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr
5454
// CHECK-SAME: , [[USIZE]]{{( noundef)?}} %[[BYTES]])
5555
x == y
5656
}
5757

5858
// CHECK-LABEL: @eq_slice_of_i32(
59-
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
60-
// CHECK-SAME: [[USIZE]] noundef %3
59+
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %x.1
60+
// CHECK-SAME: [[USIZE]] noundef %y.1
6161
#[no_mangle]
6262
fn eq_slice_of_i32(x: &[i32], y: &[i32]) -> bool {
63-
// CHECK: icmp eq [[USIZE]] %1, %3
64-
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 2
63+
// CHECK: icmp eq [[USIZE]] %x.1, %y.1
64+
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %x.1, 2
6565
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr
6666
// CHECK-SAME: , [[USIZE]]{{( noundef)?}} %[[BYTES]])
6767
x == y
6868
}
6969

7070
// CHECK-LABEL: @eq_slice_of_nonzero(
71-
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
72-
// CHECK-SAME: [[USIZE]] noundef %3
71+
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %x.1
72+
// CHECK-SAME: [[USIZE]] noundef %y.1
7373
#[no_mangle]
7474
fn eq_slice_of_nonzero(x: &[NonZeroU32], y: &[NonZeroU32]) -> bool {
75-
// CHECK: icmp eq [[USIZE]] %1, %3
76-
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 2
75+
// CHECK: icmp eq [[USIZE]] %x.1, %y.1
76+
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %x.1, 2
7777
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr
7878
// CHECK-SAME: , [[USIZE]]{{( noundef)?}} %[[BYTES]])
7979
x == y
8080
}
8181

8282
// CHECK-LABEL: @eq_slice_of_option_of_nonzero(
83-
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
84-
// CHECK-SAME: [[USIZE]] noundef %3
83+
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %x.1
84+
// CHECK-SAME: [[USIZE]] noundef %y.1
8585
#[no_mangle]
8686
fn eq_slice_of_option_of_nonzero(x: &[Option<NonZeroI16>], y: &[Option<NonZeroI16>]) -> bool {
87-
// CHECK: icmp eq [[USIZE]] %1, %3
88-
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 1
87+
// CHECK: icmp eq [[USIZE]] %x.1, %y.1
88+
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %x.1, 1
8989
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr
9090
// CHECK-SAME: , [[USIZE]]{{( noundef)?}} %[[BYTES]])
9191
x == y

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
}
9090
}
9191

92-
alloc11 (size: 4, align: 2) {
92+
alloc8 (size: 4, align: 2) {
9393
01 00 63 00 │ ..c.
9494
}
9595

tests/mir-opt/const_prop/boolean_identities.test.ConstProp.diff

+5-7
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@
77
let mut _0: bool;
88
let mut _3: bool;
99
let mut _4: bool;
10-
let mut _5: bool;
11-
let mut _6: bool;
1210

1311
bb0: {
1412
StorageLive(_3);
1513
- _3 = BitOr(_2, const true);
1614
+ _3 = const true;
17-
StorageLive(_5);
18-
- _5 = BitAnd(_1, const false);
19-
- _0 = BitAnd(move _3, move _5);
20-
+ _5 = const false;
15+
StorageLive(_4);
16+
- _4 = BitAnd(_1, const false);
17+
- _0 = BitAnd(move _3, move _4);
18+
+ _4 = const false;
2119
+ _0 = const false;
22-
StorageDead(_5);
20+
StorageDead(_4);
2321
StorageDead(_3);
2422
return;
2523
}

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

+5-15
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,17 @@
44
fn main() -> () {
55
let mut _0: ();
66
let _1: ();
7-
let mut _2: ((), u8, u8);
87

98
bb0: {
10-
StorageLive(_2);
11-
- _2 = (const (), const 0_u8, const 0_u8);
12-
- _1 = encode(move _2) -> [return: bb1, unwind unreachable];
13-
+ _2 = const ((), 0_u8, 0_u8);
14-
+ _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind unreachable];
9+
_1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind unreachable];
1510
}
1611

1712
bb1: {
18-
StorageDead(_2);
1913
return;
2014
}
21-
+ }
22-
+
23-
+ alloc8 (size: 2, align: 1) {
24-
+ 00 00 │ ..
25-
+ }
26-
+
27-
+ alloc7 (size: 2, align: 1) {
28-
+ 00 00 │ ..
15+
}
16+
17+
alloc5 (size: 2, align: 1) {
18+
00 00 │ ..
2919
}
3020

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

+5-15
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,17 @@
44
fn main() -> () {
55
let mut _0: ();
66
let _1: ();
7-
let mut _2: ((), u8, u8);
87

98
bb0: {
10-
StorageLive(_2);
11-
- _2 = (const (), const 0_u8, const 0_u8);
12-
- _1 = encode(move _2) -> [return: bb1, unwind continue];
13-
+ _2 = const ((), 0_u8, 0_u8);
14-
+ _1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind continue];
9+
_1 = encode(const ((), 0_u8, 0_u8)) -> [return: bb1, unwind continue];
1510
}
1611

1712
bb1: {
18-
StorageDead(_2);
1913
return;
2014
}
21-
+ }
22-
+
23-
+ alloc8 (size: 2, align: 1) {
24-
+ 00 00 │ ..
25-
+ }
26-
+
27-
+ alloc7 (size: 2, align: 1) {
28-
+ 00 00 │ ..
15+
}
16+
17+
alloc5 (size: 2, align: 1) {
18+
00 00 │ ..
2919
}
3020

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

+5-24
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,17 @@
44
fn main() -> () {
55
let mut _0: ();
66
let _1: ();
7-
let mut _2: ((u8, u8),);
8-
let mut _3: (u8, u8);
97

108
bb0: {
11-
StorageLive(_2);
12-
StorageLive(_3);
13-
- _3 = (const 1_u8, const 2_u8);
14-
- _2 = (move _3,);
15-
+ _3 = const (1_u8, 2_u8);
16-
+ _2 = const ((1_u8, 2_u8),);
17-
StorageDead(_3);
18-
- _1 = test(move _2) -> [return: bb1, unwind unreachable];
19-
+ _1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind unreachable];
9+
_1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind unreachable];
2010
}
2111

2212
bb1: {
23-
StorageDead(_2);
2413
return;
2514
}
26-
+ }
27-
+
28-
+ alloc12 (size: 2, align: 1) {
29-
+ 01 02 │ ..
30-
+ }
31-
+
32-
+ alloc11 (size: 2, align: 1) {
33-
+ 01 02 │ ..
34-
+ }
35-
+
36-
+ alloc8 (size: 2, align: 1) {
37-
+ 01 02 │ ..
15+
}
16+
17+
alloc7 (size: 2, align: 1) {
18+
01 02 │ ..
3819
}
3920

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

+5-24
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,17 @@
44
fn main() -> () {
55
let mut _0: ();
66
let _1: ();
7-
let mut _2: ((u8, u8),);
8-
let mut _3: (u8, u8);
97

108
bb0: {
11-
StorageLive(_2);
12-
StorageLive(_3);
13-
- _3 = (const 1_u8, const 2_u8);
14-
- _2 = (move _3,);
15-
+ _3 = const (1_u8, 2_u8);
16-
+ _2 = const ((1_u8, 2_u8),);
17-
StorageDead(_3);
18-
- _1 = test(move _2) -> [return: bb1, unwind continue];
19-
+ _1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind continue];
9+
_1 = test(const ((1_u8, 2_u8),)) -> [return: bb1, unwind continue];
2010
}
2111

2212
bb1: {
23-
StorageDead(_2);
2413
return;
2514
}
26-
+ }
27-
+
28-
+ alloc12 (size: 2, align: 1) {
29-
+ 01 02 │ ..
30-
+ }
31-
+
32-
+ alloc11 (size: 2, align: 1) {
33-
+ 01 02 │ ..
34-
+ }
35-
+
36-
+ alloc8 (size: 2, align: 1) {
37-
+ 01 02 │ ..
15+
}
16+
17+
alloc7 (size: 2, align: 1) {
18+
01 02 │ ..
3819
}
3920

tests/mir-opt/funky_arms.float_to_exponential_common.ConstProp.panic-abort.diff

+19-28
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,10 @@
1111
let mut _7: std::option::Option<usize>;
1212
let mut _8: &std::fmt::Formatter<'_>;
1313
let mut _9: isize;
14-
let mut _11: &mut std::fmt::Formatter<'_>;
15-
let mut _12: &T;
16-
let mut _13: core::num::flt2dec::Sign;
17-
let mut _14: u32;
18-
let mut _15: u32;
19-
let mut _16: usize;
20-
let mut _17: bool;
21-
let mut _18: &mut std::fmt::Formatter<'_>;
22-
let mut _19: &T;
23-
let mut _20: core::num::flt2dec::Sign;
24-
let mut _21: bool;
14+
let mut _11: core::num::flt2dec::Sign;
15+
let mut _12: u32;
16+
let mut _13: u32;
17+
let mut _14: core::num::flt2dec::Sign;
2518
scope 1 {
2619
debug force_sign => _4;
2720
let _6: core::num::flt2dec::Sign;
@@ -48,14 +41,12 @@
4841
}
4942

5043
bb2: {
51-
- _6 = MinusPlus;
52-
+ _6 = const MinusPlus;
44+
_6 = const MinusPlus;
5345
goto -> bb4;
5446
}
5547

5648
bb3: {
57-
- _6 = Minus;
58-
+ _6 = const Minus;
49+
_6 = const Minus;
5950
goto -> bb4;
6051
}
6152

@@ -74,30 +65,30 @@
7465

7566
bb6: {
7667
_10 = ((_7 as Some).0: usize);
68+
StorageLive(_11);
69+
_11 = _6;
70+
StorageLive(_12);
7771
StorageLive(_13);
78-
_13 = _6;
79-
StorageLive(_14);
80-
StorageLive(_15);
81-
_15 = _10 as u32 (IntToInt);
82-
_14 = Add(move _15, const 1_u32);
83-
StorageDead(_15);
84-
_0 = float_to_exponential_common_exact::<T>(_1, _2, move _13, move _14, _3) -> [return: bb7, unwind unreachable];
72+
_13 = _10 as u32 (IntToInt);
73+
_12 = Add(move _13, const 1_u32);
74+
StorageDead(_13);
75+
_0 = float_to_exponential_common_exact::<T>(_1, _2, move _11, move _12, _3) -> [return: bb7, unwind unreachable];
8576
}
8677

8778
bb7: {
88-
StorageDead(_14);
89-
StorageDead(_13);
79+
StorageDead(_12);
80+
StorageDead(_11);
9081
goto -> bb10;
9182
}
9283

9384
bb8: {
94-
StorageLive(_20);
95-
_20 = _6;
96-
_0 = float_to_exponential_common_shortest::<T>(_1, _2, move _20, _3) -> [return: bb9, unwind unreachable];
85+
StorageLive(_14);
86+
_14 = _6;
87+
_0 = float_to_exponential_common_shortest::<T>(_1, _2, move _14, _3) -> [return: bb9, unwind unreachable];
9788
}
9889

9990
bb9: {
100-
StorageDead(_20);
91+
StorageDead(_14);
10192
goto -> bb10;
10293
}
10394

0 commit comments

Comments
 (0)