Skip to content

Commit a03c972

Browse files
committed
Enable GVN by default.
1 parent 08cc634 commit a03c972

File tree

35 files changed

+384
-529
lines changed

35 files changed

+384
-529
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub struct GVN;
109109

110110
impl<'tcx> MirPass<'tcx> for GVN {
111111
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
112-
sess.mir_opt_level() >= 4
112+
sess.mir_opt_level() >= 2
113113
}
114114

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

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,9 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
588588
// destroy the SSA property. It should still happen before const-propagation, so the
589589
// latter pass will leverage the created opportunities.
590590
&separate_const_switch::SeparateConstSwitch,
591-
&const_prop::ConstProp,
592591
&gvn::GVN,
593592
&simplify::SimplifyLocals::AfterGVN,
593+
&const_prop::ConstProp,
594594
&dataflow_const_prop::DataflowConstProp,
595595
&const_debuginfo::ConstDebugInfo,
596596
&o1(simplify_branches::SimplifyConstCondition::AfterConstProp),

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

Lines changed: 0 additions & 2 deletions
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/coverage/async2.cov-map

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ Number of file 0 mappings: 1
77
- Code(Counter(0)) at (prev + 13, 1) to (start + 0, 23)
88

99
Function name: async2::async_func::{closure#0}
10-
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 0d, 17, 03, 09, 05, 03, 0a, 02, 06, 02, 02, 06, 00, 07, 07, 01, 01, 00, 02]
10+
Raw bytes (26): 0x[01, 01, 01, 05, 00, 04, 01, 0d, 17, 03, 09, 05, 03, 0a, 02, 06, 00, 02, 06, 00, 07, 03, 01, 01, 00, 02]
1111
Number of files: 1
1212
- file 0 => global file 1
13-
Number of expressions: 2
14-
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
15-
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
13+
Number of expressions: 1
14+
- expression 0 operands: lhs = Counter(1), rhs = Zero
1615
Number of file 0 mappings: 4
1716
- Code(Counter(0)) at (prev + 13, 23) to (start + 3, 9)
1817
- Code(Counter(1)) at (prev + 3, 10) to (start + 2, 6)
19-
- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7)
20-
= (c0 - c1)
21-
- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2)
22-
= (c1 + (c0 - c1))
18+
- Code(Zero) at (prev + 2, 6) to (start + 0, 7)
19+
- Code(Expression(0, Add)) at (prev + 1, 1) to (start + 0, 2)
20+
= (c1 + Zero)
2321

2422
Function name: async2::async_func_just_println
2523
Raw bytes (9): 0x[01, 01, 00, 01, 01, 15, 01, 00, 24]

tests/coverage/partial_eq.cov-map

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ Number of file 0 mappings: 2
2525
- Code(Zero) at (prev + 0, 32) to (start + 0, 33)
2626

2727
Function name: <partial_eq::Version as core::cmp::PartialOrd>::partial_cmp
28-
Raw bytes (22): 0x[01, 01, 04, 07, 0b, 05, 09, 0f, 15, 0d, 11, 02, 01, 04, 27, 00, 28, 03, 00, 30, 00, 31]
28+
Raw bytes (22): 0x[01, 01, 04, 07, 0b, 00, 09, 0f, 15, 00, 11, 02, 01, 04, 27, 00, 28, 03, 00, 30, 00, 31]
2929
Number of files: 1
3030
- file 0 => global file 1
3131
Number of expressions: 4
3232
- expression 0 operands: lhs = Expression(1, Add), rhs = Expression(2, Add)
33-
- expression 1 operands: lhs = Counter(1), rhs = Counter(2)
33+
- expression 1 operands: lhs = Zero, rhs = Counter(2)
3434
- expression 2 operands: lhs = Expression(3, Add), rhs = Counter(5)
35-
- expression 3 operands: lhs = Counter(3), rhs = Counter(4)
35+
- expression 3 operands: lhs = Zero, rhs = Counter(4)
3636
Number of file 0 mappings: 2
3737
- Code(Counter(0)) at (prev + 4, 39) to (start + 0, 40)
3838
- Code(Expression(0, Add)) at (prev + 0, 48) to (start + 0, 49)
39-
= ((c1 + c2) + ((c3 + c4) + c5))
39+
= ((Zero + c2) + ((Zero + c4) + c5))
4040

4141
Function name: <partial_eq::Version as core::fmt::Debug>::fmt
4242
Raw bytes (9): 0x[01, 01, 00, 01, 01, 04, 11, 00, 16]

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

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,10 @@
99
let _4: bool;
1010
let mut _6: std::option::Option<usize>;
1111
let mut _7: isize;
12-
let mut _9: &mut std::fmt::Formatter<'_>;
13-
let mut _10: &T;
14-
let mut _11: core::num::flt2dec::Sign;
15-
let mut _12: u32;
16-
let mut _13: u32;
17-
let mut _14: usize;
18-
let mut _15: bool;
19-
let mut _16: &mut std::fmt::Formatter<'_>;
20-
let mut _17: &T;
21-
let mut _18: core::num::flt2dec::Sign;
22-
let mut _19: bool;
12+
let mut _9: core::num::flt2dec::Sign;
13+
let mut _10: u32;
14+
let mut _11: u32;
15+
let mut _12: core::num::flt2dec::Sign;
2316
scope 1 {
2417
debug force_sign => _4;
2518
let _5: core::num::flt2dec::Sign;
@@ -36,32 +29,30 @@
3629
}
3730
scope 4 (inlined Formatter::<'_>::sign_plus) {
3831
debug self => _1;
39-
let mut _20: u32;
40-
let mut _21: u32;
32+
let mut _13: u32;
33+
let mut _14: u32;
4134
}
4235

4336
bb0: {
4437
StorageLive(_4);
45-
StorageLive(_20);
46-
StorageLive(_21);
47-
_21 = ((*_1).0: u32);
48-
_20 = BitAnd(move _21, const 1_u32);
49-
StorageDead(_21);
50-
_4 = Ne(move _20, const 0_u32);
51-
StorageDead(_20);
38+
StorageLive(_13);
39+
StorageLive(_14);
40+
_14 = ((*_1).0: u32);
41+
_13 = BitAnd(move _14, const 1_u32);
42+
StorageDead(_14);
43+
_4 = Ne(move _13, const 0_u32);
44+
StorageDead(_13);
5245
StorageLive(_5);
5346
switchInt(_4) -> [0: bb2, otherwise: bb1];
5447
}
5548

5649
bb1: {
57-
- _5 = MinusPlus;
58-
+ _5 = const MinusPlus;
50+
_5 = const MinusPlus;
5951
goto -> bb3;
6052
}
6153

6254
bb2: {
63-
- _5 = Minus;
64-
+ _5 = const Minus;
55+
_5 = const Minus;
6556
goto -> bb3;
6657
}
6758

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

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

8778
bb5: {
88-
StorageDead(_12);
89-
StorageDead(_11);
79+
StorageDead(_10);
80+
StorageDead(_9);
9081
goto -> bb8;
9182
}
9283

9384
bb6: {
94-
StorageLive(_18);
95-
_18 = _5;
96-
_0 = float_to_exponential_common_shortest::<T>(_1, _2, move _18, _3) -> [return: bb7, unwind unreachable];
85+
StorageLive(_12);
86+
_12 = _5;
87+
_0 = float_to_exponential_common_shortest::<T>(_1, _2, move _12, _3) -> [return: bb7, unwind unreachable];
9788
}
9889

9990
bb7: {
100-
StorageDead(_18);
91+
StorageDead(_12);
10192
goto -> bb8;
10293
}
10394

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

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,10 @@
99
let _4: bool;
1010
let mut _6: std::option::Option<usize>;
1111
let mut _7: isize;
12-
let mut _9: &mut std::fmt::Formatter<'_>;
13-
let mut _10: &T;
14-
let mut _11: core::num::flt2dec::Sign;
15-
let mut _12: u32;
16-
let mut _13: u32;
17-
let mut _14: usize;
18-
let mut _15: bool;
19-
let mut _16: &mut std::fmt::Formatter<'_>;
20-
let mut _17: &T;
21-
let mut _18: core::num::flt2dec::Sign;
22-
let mut _19: bool;
12+
let mut _9: core::num::flt2dec::Sign;
13+
let mut _10: u32;
14+
let mut _11: u32;
15+
let mut _12: core::num::flt2dec::Sign;
2316
scope 1 {
2417
debug force_sign => _4;
2518
let _5: core::num::flt2dec::Sign;
@@ -36,32 +29,30 @@
3629
}
3730
scope 4 (inlined Formatter::<'_>::sign_plus) {
3831
debug self => _1;
39-
let mut _20: u32;
40-
let mut _21: u32;
32+
let mut _13: u32;
33+
let mut _14: u32;
4134
}
4235

4336
bb0: {
4437
StorageLive(_4);
45-
StorageLive(_20);
46-
StorageLive(_21);
47-
_21 = ((*_1).0: u32);
48-
_20 = BitAnd(move _21, const 1_u32);
49-
StorageDead(_21);
50-
_4 = Ne(move _20, const 0_u32);
51-
StorageDead(_20);
38+
StorageLive(_13);
39+
StorageLive(_14);
40+
_14 = ((*_1).0: u32);
41+
_13 = BitAnd(move _14, const 1_u32);
42+
StorageDead(_14);
43+
_4 = Ne(move _13, const 0_u32);
44+
StorageDead(_13);
5245
StorageLive(_5);
5346
switchInt(_4) -> [0: bb2, otherwise: bb1];
5447
}
5548

5649
bb1: {
57-
- _5 = MinusPlus;
58-
+ _5 = const MinusPlus;
50+
_5 = const MinusPlus;
5951
goto -> bb3;
6052
}
6153

6254
bb2: {
63-
- _5 = Minus;
64-
+ _5 = const Minus;
55+
_5 = const Minus;
6556
goto -> bb3;
6657
}
6758

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

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

8778
bb5: {
88-
StorageDead(_12);
89-
StorageDead(_11);
79+
StorageDead(_10);
80+
StorageDead(_9);
9081
goto -> bb8;
9182
}
9283

9384
bb6: {
94-
StorageLive(_18);
95-
_18 = _5;
96-
_0 = float_to_exponential_common_shortest::<T>(_1, _2, move _18, _3) -> [return: bb7, unwind continue];
85+
StorageLive(_12);
86+
_12 = _5;
87+
_0 = float_to_exponential_common_shortest::<T>(_1, _2, move _12, _3) -> [return: bb7, unwind continue];
9788
}
9889

9990
bb7: {
100-
StorageDead(_18);
91+
StorageDead(_12);
10192
goto -> bb8;
10293
}
10394

tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn b(_1: &mut Box<T>) -> &mut T {
1919
_4 = &mut (*_1);
2020
StorageLive(_5);
2121
StorageLive(_6);
22-
_5 = deref_copy (*_4);
22+
_5 = (*_4);
2323
_6 = (((_5.0: std::ptr::Unique<T>).0: std::ptr::NonNull<T>).0: *const T);
2424
_3 = &mut (*_6);
2525
StorageDead(_6);

tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn d(_1: &Box<T>) -> &T {
1717
_3 = &(*_1);
1818
StorageLive(_4);
1919
StorageLive(_5);
20-
_4 = deref_copy (*_3);
20+
_4 = (*_3);
2121
_5 = (((_4.0: std::ptr::Unique<T>).0: std::ptr::NonNull<T>).0: *const T);
2222
_2 = &(*_5);
2323
StorageDead(_5);

0 commit comments

Comments
 (0)