Skip to content

Commit 7f4f652

Browse files
committed
Auto merge of rust-lang#132527 - DianQK:gvn-stmt-iter, r=oli-obk
gvn: Invalid dereferences for all non-local mutations Fixes rust-lang#132353. This PR removes the computation value by traversing SSA locals through `for_each_assignment_mut`. Because the `for_each_assignment_mut` traversal skips statements which have side effects, such as dereference assignments, the computation may be unsound. Instead of `for_each_assignment_mut`, we compute values by traversing in reverse postorder. Because we compute and use the symbolic representation of values on the fly, I invalidate all old values when encountering a dereference assignment. The current approach does not prevent the optimization of a clone to a copy. In the future, we may add an alias model, or dominance information for dereference assignments, or SSA form to help GVN. r? cjgillot cc `@jieyouxu` rust-lang#132356 cc `@RalfJung` rust-lang#133474
2 parents d5b4c2e + d9fbe5d commit 7f4f652

File tree

43 files changed

+555
-567
lines changed

Some content is hidden

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

43 files changed

+555
-567
lines changed

compiler/rustc_data_structures/src/fx.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub type FxIndexSet<V> = indexmap::IndexSet<V, BuildHasherDefault<FxHasher>>;
99
pub type IndexEntry<'a, K, V> = indexmap::map::Entry<'a, K, V>;
1010
pub type IndexOccupiedEntry<'a, K, V> = indexmap::map::OccupiedEntry<'a, K, V>;
1111

12+
pub use indexmap::set::MutableValues;
13+
1214
#[macro_export]
1315
macro_rules! define_id_collections {
1416
($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty) => {

compiler/rustc_mir_transform/src/gvn.rs

+110-92
Large diffs are not rendered by default.

compiler/rustc_mir_transform/src/ssa.rs

-38
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ pub(super) struct SsaLocals {
3232
borrowed_locals: DenseBitSet<Local>,
3333
}
3434

35-
pub(super) enum AssignedValue<'a, 'tcx> {
36-
Arg,
37-
Rvalue(&'a mut Rvalue<'tcx>),
38-
Terminator,
39-
}
40-
4135
impl SsaLocals {
4236
pub(super) fn new<'tcx>(
4337
tcx: TyCtxt<'tcx>,
@@ -152,38 +146,6 @@ impl SsaLocals {
152146
})
153147
}
154148

155-
pub(super) fn for_each_assignment_mut<'tcx>(
156-
&self,
157-
basic_blocks: &mut IndexSlice<BasicBlock, BasicBlockData<'tcx>>,
158-
mut f: impl FnMut(Local, AssignedValue<'_, 'tcx>, Location),
159-
) {
160-
for &local in &self.assignment_order {
161-
match self.assignments[local] {
162-
Set1::One(DefLocation::Argument) => f(
163-
local,
164-
AssignedValue::Arg,
165-
Location { block: START_BLOCK, statement_index: 0 },
166-
),
167-
Set1::One(DefLocation::Assignment(loc)) => {
168-
let bb = &mut basic_blocks[loc.block];
169-
// `loc` must point to a direct assignment to `local`.
170-
let stmt = &mut bb.statements[loc.statement_index];
171-
let StatementKind::Assign(box (target, ref mut rvalue)) = stmt.kind else {
172-
bug!()
173-
};
174-
assert_eq!(target.as_local(), Some(local));
175-
f(local, AssignedValue::Rvalue(rvalue), loc)
176-
}
177-
Set1::One(DefLocation::CallReturn { call, .. }) => {
178-
let bb = &mut basic_blocks[call];
179-
let loc = Location { block: call, statement_index: bb.statements.len() };
180-
f(local, AssignedValue::Terminator, loc)
181-
}
182-
_ => {}
183-
}
184-
}
185-
}
186-
187149
/// Compute the equivalence classes for locals, based on copy statements.
188150
///
189151
/// The returned vector maps each local to the one it copies. In the following case:

tests/codegen/clone_as_copy.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//@ revisions: DEBUGINFO NODEBUGINFO
2-
//@ compile-flags: -Zunsound-mir-opts
3-
// FIXME: see <https://github.com/rust-lang/rust/issues/132353>
42
//@ compile-flags: -Copt-level=3 -Cno-prepopulate-passes
53
//@ [DEBUGINFO] compile-flags: -Cdebuginfo=full
64

tests/codegen/try_question_mark_nop.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ use std::ptr::NonNull;
1616
#[no_mangle]
1717
pub fn option_nop_match_32(x: Option<u32>) -> Option<u32> {
1818
// CHECK: start:
19-
// TWENTY-NEXT: %[[IS_SOME:.+]] = trunc nuw i32 %0 to i1
20-
// TWENTY-NEXT: %[[PAYLOAD:.+]] = select i1 %[[IS_SOME]], i32 %1, i32 undef
21-
// CHECK-NEXT: [[REG1:%.*]] = insertvalue { i32, i32 } poison, i32 %0, 0
22-
// NINETEEN-NEXT: [[REG2:%.*]] = insertvalue { i32, i32 } [[REG1]], i32 %1, 1
23-
// TWENTY-NEXT: [[REG2:%.*]] = insertvalue { i32, i32 } [[REG1]], i32 %[[PAYLOAD]], 1
24-
// CHECK-NEXT: ret { i32, i32 } [[REG2]]
19+
// CHECK-NEXT: [[TRUNC:%.*]] = trunc nuw i32 %0 to i1
20+
21+
// NINETEEN-NEXT: [[SELECT:%.*]] = select i1 [[TRUNC]], i32 %0, i32 0
22+
// NINETEEN-NEXT: [[REG2:%.*]] = insertvalue { i32, i32 } poison, i32 [[SELECT]], 0
23+
// NINETEEN-NEXT: [[REG3:%.*]] = insertvalue { i32, i32 } [[REG2]], i32 %1, 1
24+
25+
// TWENTY-NEXT: [[SELECT:%.*]] = select i1 [[TRUNC]], i32 %1, i32 undef
26+
// TWENTY-NEXT: [[REG2:%.*]] = insertvalue { i32, i32 } poison, i32 %0, 0
27+
// TWENTY-NEXT: [[REG3:%.*]] = insertvalue { i32, i32 } [[REG2]], i32 [[SELECT]], 1
28+
29+
// CHECK-NEXT: ret { i32, i32 } [[REG3]]
2530
match x {
2631
Some(x) => Some(x),
2732
None => None,
@@ -164,8 +169,8 @@ pub fn control_flow_nop_traits_64(x: ControlFlow<i64, u64>) -> ControlFlow<i64,
164169
#[no_mangle]
165170
pub fn result_nop_match_128(x: Result<i128, u128>) -> Result<i128, u128> {
166171
// CHECK: start:
167-
// CHECK-NEXT: getelementptr inbounds {{(nuw )?}}i8
168172
// CHECK-NEXT: store i128
173+
// CHECK-NEXT: getelementptr inbounds {{(nuw )?}}i8
169174
// CHECK-NEXT: store i128
170175
// CHECK-NEXT: ret void
171176
match x {
@@ -189,8 +194,8 @@ pub fn result_nop_traits_128(x: Result<i128, u128>) -> Result<i128, u128> {
189194
#[no_mangle]
190195
pub fn control_flow_nop_match_128(x: ControlFlow<i128, u128>) -> ControlFlow<i128, u128> {
191196
// CHECK: start:
192-
// CHECK-NEXT: getelementptr inbounds {{(nuw )?}}i8
193197
// CHECK-NEXT: store i128
198+
// CHECK-NEXT: getelementptr inbounds {{(nuw )?}}i8
194199
// CHECK-NEXT: store i128
195200
// CHECK-NEXT: ret void
196201
match x {

tests/coverage/issue-84561.cov-map

+67-96
Original file line numberDiff line numberDiff line change
@@ -59,109 +59,80 @@ Number of file 0 mappings: 1
5959
Highest counter ID seen: c0
6060

6161
Function name: issue_84561::test3
62-
Raw bytes (315): 0x[01, 01, 1b, 1d, 21, 25, 29, 21, 25, 2d, 31, 21, 17, 25, 2d, 41, 45, 49, 4d, 51, 55, 33, 51, 49, 4d, 33, 37, 49, 4d, 51, 59, 55, 59, 55, 59, 47, 5d, 55, 59, 61, 65, 71, 75, 69, 6d, 69, 6d, 69, 6d, 63, 79, 71, 75, 79, 7d, 7d, 81, 01, 33, 01, 08, 01, 03, 0f, 05, 04, 09, 01, 0f, 09, 02, 05, 04, 0f, 0d, 05, 05, 00, 0f, 11, 01, 05, 00, 0f, 15, 01, 09, 01, 0f, 19, 02, 05, 00, 0f, 1d, 01, 05, 00, 0f, 02, 00, 20, 00, 30, 21, 01, 05, 03, 0f, 25, 03, 20, 00, 30, 29, 00, 33, 00, 41, 06, 00, 4b, 00, 5a, 0a, 01, 05, 00, 0f, 2d, 05, 09, 03, 10, 31, 05, 0d, 00, 1b, 0e, 02, 0d, 00, 1c, 12, 04, 09, 02, 0f, 35, 06, 05, 00, 0f, 39, 04, 05, 00, 0f, 3d, 04, 09, 01, 0f, 41, 05, 08, 00, 0f, 45, 01, 09, 00, 13, 1a, 05, 09, 00, 13, 33, 05, 08, 00, 0f, 51, 01, 09, 00, 13, 22, 03, 0d, 00, 1d, 26, 03, 09, 00, 13, 2e, 03, 0d, 00, 1d, 47, 03, 05, 00, 0f, 47, 01, 0c, 00, 13, 5d, 01, 0d, 00, 13, 42, 02, 0d, 00, 13, 61, 04, 05, 02, 13, 65, 03, 0d, 00, 13, 4a, 02, 0d, 00, 13, 63, 03, 05, 00, 0f, 69, 01, 0c, 00, 13, 6d, 01, 0d, 00, 17, 71, 04, 0d, 00, 13, 5a, 02, 0d, 00, 17, 5a, 01, 14, 00, 1b, 00, 01, 15, 00, 1b, 5a, 02, 15, 00, 1b, 75, 04, 0d, 00, 13, 5e, 03, 09, 00, 19, 79, 02, 05, 00, 0f, 66, 03, 09, 00, 22, 7d, 02, 05, 00, 0f, 6a, 03, 09, 00, 2c, 81, 01, 02, 01, 00, 02]
62+
Raw bytes (279): 0x[01, 01, 0a, 0d, 11, 0d, 15, 0d, 19, 1d, 21, 29, 2d, 25, 29, 25, 29, 25, 29, 27, 31, 29, 2d, 33, 01, 08, 01, 03, 0f, 05, 04, 09, 01, 0f, 09, 02, 05, 04, 0f, 09, 05, 05, 00, 0f, 09, 01, 05, 00, 0f, 09, 01, 09, 01, 0f, 0d, 02, 05, 00, 0f, 0d, 01, 05, 00, 0f, 00, 00, 20, 00, 30, 0d, 01, 05, 03, 0f, 00, 03, 20, 00, 30, 00, 00, 33, 00, 41, 00, 00, 4b, 00, 5a, 0d, 01, 05, 00, 0f, 00, 05, 09, 03, 10, 00, 05, 0d, 00, 1b, 00, 02, 0d, 00, 1c, 0d, 04, 09, 02, 0f, 0d, 06, 05, 00, 0f, 0d, 04, 05, 00, 0f, 0d, 04, 09, 01, 0f, 0d, 05, 08, 00, 0f, 11, 01, 09, 00, 13, 02, 05, 09, 00, 13, 0d, 05, 08, 00, 0f, 15, 01, 09, 00, 13, 00, 03, 0d, 00, 1d, 06, 03, 09, 00, 13, 00, 03, 0d, 00, 1d, 0d, 03, 05, 00, 0f, 0d, 01, 0c, 00, 13, 19, 01, 0d, 00, 13, 0a, 02, 0d, 00, 13, 1d, 04, 05, 02, 13, 21, 03, 0d, 00, 13, 0e, 02, 0d, 00, 13, 27, 03, 05, 00, 0f, 25, 01, 0c, 00, 13, 29, 01, 0d, 00, 17, 29, 04, 0d, 00, 13, 1e, 02, 0d, 00, 17, 1e, 01, 14, 00, 1b, 00, 01, 15, 00, 1b, 1e, 02, 15, 00, 1b, 2d, 04, 0d, 00, 13, 22, 03, 09, 00, 19, 31, 02, 05, 00, 0f, 31, 03, 09, 00, 22, 00, 02, 05, 00, 0f, 00, 03, 09, 00, 2c, 00, 02, 01, 00, 02]
6363
Number of files: 1
6464
- file 0 => global file 1
65-
Number of expressions: 27
66-
- expression 0 operands: lhs = Counter(7), rhs = Counter(8)
67-
- expression 1 operands: lhs = Counter(9), rhs = Counter(10)
68-
- expression 2 operands: lhs = Counter(8), rhs = Counter(9)
69-
- expression 3 operands: lhs = Counter(11), rhs = Counter(12)
70-
- expression 4 operands: lhs = Counter(8), rhs = Expression(5, Add)
71-
- expression 5 operands: lhs = Counter(9), rhs = Counter(11)
72-
- expression 6 operands: lhs = Counter(16), rhs = Counter(17)
73-
- expression 7 operands: lhs = Counter(18), rhs = Counter(19)
74-
- expression 8 operands: lhs = Counter(20), rhs = Counter(21)
75-
- expression 9 operands: lhs = Expression(12, Add), rhs = Counter(20)
76-
- expression 10 operands: lhs = Counter(18), rhs = Counter(19)
77-
- expression 11 operands: lhs = Expression(12, Add), rhs = Expression(13, Add)
78-
- expression 12 operands: lhs = Counter(18), rhs = Counter(19)
79-
- expression 13 operands: lhs = Counter(20), rhs = Counter(22)
80-
- expression 14 operands: lhs = Counter(21), rhs = Counter(22)
81-
- expression 15 operands: lhs = Counter(21), rhs = Counter(22)
82-
- expression 16 operands: lhs = Expression(17, Add), rhs = Counter(23)
83-
- expression 17 operands: lhs = Counter(21), rhs = Counter(22)
84-
- expression 18 operands: lhs = Counter(24), rhs = Counter(25)
85-
- expression 19 operands: lhs = Counter(28), rhs = Counter(29)
86-
- expression 20 operands: lhs = Counter(26), rhs = Counter(27)
87-
- expression 21 operands: lhs = Counter(26), rhs = Counter(27)
88-
- expression 22 operands: lhs = Counter(26), rhs = Counter(27)
89-
- expression 23 operands: lhs = Expression(24, Add), rhs = Counter(30)
90-
- expression 24 operands: lhs = Counter(28), rhs = Counter(29)
91-
- expression 25 operands: lhs = Counter(30), rhs = Counter(31)
92-
- expression 26 operands: lhs = Counter(31), rhs = Counter(32)
65+
Number of expressions: 10
66+
- expression 0 operands: lhs = Counter(3), rhs = Counter(4)
67+
- expression 1 operands: lhs = Counter(3), rhs = Counter(5)
68+
- expression 2 operands: lhs = Counter(3), rhs = Counter(6)
69+
- expression 3 operands: lhs = Counter(7), rhs = Counter(8)
70+
- expression 4 operands: lhs = Counter(10), rhs = Counter(11)
71+
- expression 5 operands: lhs = Counter(9), rhs = Counter(10)
72+
- expression 6 operands: lhs = Counter(9), rhs = Counter(10)
73+
- expression 7 operands: lhs = Counter(9), rhs = Counter(10)
74+
- expression 8 operands: lhs = Expression(9, Add), rhs = Counter(12)
75+
- expression 9 operands: lhs = Counter(10), rhs = Counter(11)
9376
Number of file 0 mappings: 51
9477
- Code(Counter(0)) at (prev + 8, 1) to (start + 3, 15)
9578
- Code(Counter(1)) at (prev + 4, 9) to (start + 1, 15)
9679
- Code(Counter(2)) at (prev + 2, 5) to (start + 4, 15)
97-
- Code(Counter(3)) at (prev + 5, 5) to (start + 0, 15)
98-
- Code(Counter(4)) at (prev + 1, 5) to (start + 0, 15)
99-
- Code(Counter(5)) at (prev + 1, 9) to (start + 1, 15)
100-
- Code(Counter(6)) at (prev + 2, 5) to (start + 0, 15)
101-
- Code(Counter(7)) at (prev + 1, 5) to (start + 0, 15)
102-
- Code(Expression(0, Sub)) at (prev + 0, 32) to (start + 0, 48)
80+
- Code(Counter(2)) at (prev + 5, 5) to (start + 0, 15)
81+
- Code(Counter(2)) at (prev + 1, 5) to (start + 0, 15)
82+
- Code(Counter(2)) at (prev + 1, 9) to (start + 1, 15)
83+
- Code(Counter(3)) at (prev + 2, 5) to (start + 0, 15)
84+
- Code(Counter(3)) at (prev + 1, 5) to (start + 0, 15)
85+
- Code(Zero) at (prev + 0, 32) to (start + 0, 48)
86+
- Code(Counter(3)) at (prev + 1, 5) to (start + 3, 15)
87+
- Code(Zero) at (prev + 3, 32) to (start + 0, 48)
88+
- Code(Zero) at (prev + 0, 51) to (start + 0, 65)
89+
- Code(Zero) at (prev + 0, 75) to (start + 0, 90)
90+
- Code(Counter(3)) at (prev + 1, 5) to (start + 0, 15)
91+
- Code(Zero) at (prev + 5, 9) to (start + 3, 16)
92+
- Code(Zero) at (prev + 5, 13) to (start + 0, 27)
93+
- Code(Zero) at (prev + 2, 13) to (start + 0, 28)
94+
- Code(Counter(3)) at (prev + 4, 9) to (start + 2, 15)
95+
- Code(Counter(3)) at (prev + 6, 5) to (start + 0, 15)
96+
- Code(Counter(3)) at (prev + 4, 5) to (start + 0, 15)
97+
- Code(Counter(3)) at (prev + 4, 9) to (start + 1, 15)
98+
- Code(Counter(3)) at (prev + 5, 8) to (start + 0, 15)
99+
- Code(Counter(4)) at (prev + 1, 9) to (start + 0, 19)
100+
- Code(Expression(0, Sub)) at (prev + 5, 9) to (start + 0, 19)
101+
= (c3 - c4)
102+
- Code(Counter(3)) at (prev + 5, 8) to (start + 0, 15)
103+
- Code(Counter(5)) at (prev + 1, 9) to (start + 0, 19)
104+
- Code(Zero) at (prev + 3, 13) to (start + 0, 29)
105+
- Code(Expression(1, Sub)) at (prev + 3, 9) to (start + 0, 19)
106+
= (c3 - c5)
107+
- Code(Zero) at (prev + 3, 13) to (start + 0, 29)
108+
- Code(Counter(3)) at (prev + 3, 5) to (start + 0, 15)
109+
- Code(Counter(3)) at (prev + 1, 12) to (start + 0, 19)
110+
- Code(Counter(6)) at (prev + 1, 13) to (start + 0, 19)
111+
- Code(Expression(2, Sub)) at (prev + 2, 13) to (start + 0, 19)
112+
= (c3 - c6)
113+
- Code(Counter(7)) at (prev + 4, 5) to (start + 2, 19)
114+
- Code(Counter(8)) at (prev + 3, 13) to (start + 0, 19)
115+
- Code(Expression(3, Sub)) at (prev + 2, 13) to (start + 0, 19)
103116
= (c7 - c8)
104-
- Code(Counter(8)) at (prev + 1, 5) to (start + 3, 15)
105-
- Code(Counter(9)) at (prev + 3, 32) to (start + 0, 48)
106-
- Code(Counter(10)) at (prev + 0, 51) to (start + 0, 65)
107-
- Code(Expression(1, Sub)) at (prev + 0, 75) to (start + 0, 90)
117+
- Code(Expression(9, Add)) at (prev + 3, 5) to (start + 0, 15)
118+
= (c10 + c11)
119+
- Code(Counter(9)) at (prev + 1, 12) to (start + 0, 19)
120+
- Code(Counter(10)) at (prev + 1, 13) to (start + 0, 23)
121+
- Code(Counter(10)) at (prev + 4, 13) to (start + 0, 19)
122+
- Code(Expression(7, Sub)) at (prev + 2, 13) to (start + 0, 23)
123+
= (c9 - c10)
124+
- Code(Expression(7, Sub)) at (prev + 1, 20) to (start + 0, 27)
108125
= (c9 - c10)
109-
- Code(Expression(2, Sub)) at (prev + 1, 5) to (start + 0, 15)
110-
= (c8 - c9)
111-
- Code(Counter(11)) at (prev + 5, 9) to (start + 3, 16)
112-
- Code(Counter(12)) at (prev + 5, 13) to (start + 0, 27)
113-
- Code(Expression(3, Sub)) at (prev + 2, 13) to (start + 0, 28)
114-
= (c11 - c12)
115-
- Code(Expression(4, Sub)) at (prev + 4, 9) to (start + 2, 15)
116-
= (c8 - (c9 + c11))
117-
- Code(Counter(13)) at (prev + 6, 5) to (start + 0, 15)
118-
- Code(Counter(14)) at (prev + 4, 5) to (start + 0, 15)
119-
- Code(Counter(15)) at (prev + 4, 9) to (start + 1, 15)
120-
- Code(Counter(16)) at (prev + 5, 8) to (start + 0, 15)
121-
- Code(Counter(17)) at (prev + 1, 9) to (start + 0, 19)
122-
- Code(Expression(6, Sub)) at (prev + 5, 9) to (start + 0, 19)
123-
= (c16 - c17)
124-
- Code(Expression(12, Add)) at (prev + 5, 8) to (start + 0, 15)
125-
= (c18 + c19)
126-
- Code(Counter(20)) at (prev + 1, 9) to (start + 0, 19)
127-
- Code(Expression(8, Sub)) at (prev + 3, 13) to (start + 0, 29)
128-
= (c20 - c21)
129-
- Code(Expression(9, Sub)) at (prev + 3, 9) to (start + 0, 19)
130-
= ((c18 + c19) - c20)
131-
- Code(Expression(11, Sub)) at (prev + 3, 13) to (start + 0, 29)
132-
= ((c18 + c19) - (c20 + c22))
133-
- Code(Expression(17, Add)) at (prev + 3, 5) to (start + 0, 15)
134-
= (c21 + c22)
135-
- Code(Expression(17, Add)) at (prev + 1, 12) to (start + 0, 19)
136-
= (c21 + c22)
137-
- Code(Counter(23)) at (prev + 1, 13) to (start + 0, 19)
138-
- Code(Expression(16, Sub)) at (prev + 2, 13) to (start + 0, 19)
139-
= ((c21 + c22) - c23)
140-
- Code(Counter(24)) at (prev + 4, 5) to (start + 2, 19)
141-
- Code(Counter(25)) at (prev + 3, 13) to (start + 0, 19)
142-
- Code(Expression(18, Sub)) at (prev + 2, 13) to (start + 0, 19)
143-
= (c24 - c25)
144-
- Code(Expression(24, Add)) at (prev + 3, 5) to (start + 0, 15)
145-
= (c28 + c29)
146-
- Code(Counter(26)) at (prev + 1, 12) to (start + 0, 19)
147-
- Code(Counter(27)) at (prev + 1, 13) to (start + 0, 23)
148-
- Code(Counter(28)) at (prev + 4, 13) to (start + 0, 19)
149-
- Code(Expression(22, Sub)) at (prev + 2, 13) to (start + 0, 23)
150-
= (c26 - c27)
151-
- Code(Expression(22, Sub)) at (prev + 1, 20) to (start + 0, 27)
152-
= (c26 - c27)
153126
- Code(Zero) at (prev + 1, 21) to (start + 0, 27)
154-
- Code(Expression(22, Sub)) at (prev + 2, 21) to (start + 0, 27)
155-
= (c26 - c27)
156-
- Code(Counter(29)) at (prev + 4, 13) to (start + 0, 19)
157-
- Code(Expression(23, Sub)) at (prev + 3, 9) to (start + 0, 25)
158-
= ((c28 + c29) - c30)
159-
- Code(Counter(30)) at (prev + 2, 5) to (start + 0, 15)
160-
- Code(Expression(25, Sub)) at (prev + 3, 9) to (start + 0, 34)
161-
= (c30 - c31)
162-
- Code(Counter(31)) at (prev + 2, 5) to (start + 0, 15)
163-
- Code(Expression(26, Sub)) at (prev + 3, 9) to (start + 0, 44)
164-
= (c31 - c32)
165-
- Code(Counter(32)) at (prev + 2, 1) to (start + 0, 2)
166-
Highest counter ID seen: c32
127+
- Code(Expression(7, Sub)) at (prev + 2, 21) to (start + 0, 27)
128+
= (c9 - c10)
129+
- Code(Counter(11)) at (prev + 4, 13) to (start + 0, 19)
130+
- Code(Expression(8, Sub)) at (prev + 3, 9) to (start + 0, 25)
131+
= ((c10 + c11) - c12)
132+
- Code(Counter(12)) at (prev + 2, 5) to (start + 0, 15)
133+
- Code(Counter(12)) at (prev + 3, 9) to (start + 0, 34)
134+
- Code(Zero) at (prev + 2, 5) to (start + 0, 15)
135+
- Code(Zero) at (prev + 3, 9) to (start + 0, 44)
136+
- Code(Zero) at (prev + 2, 1) to (start + 0, 2)
137+
Highest counter ID seen: c12
167138

tests/mir-opt/const_prop/control_flow_simplification.hello.GVN.panic-abort.diff

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
bb0: {
1010
StorageLive(_1);
11-
_1 = const <bool as NeedsDrop>::NEEDS;
11+
- _1 = const <bool as NeedsDrop>::NEEDS;
1212
- switchInt(move _1) -> [0: bb2, otherwise: bb1];
13+
+ _1 = const false;
1314
+ switchInt(const false) -> [0: bb2, otherwise: bb1];
1415
}
1516

tests/mir-opt/const_prop/control_flow_simplification.hello.GVN.panic-unwind.diff

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
bb0: {
1010
StorageLive(_1);
11-
_1 = const <bool as NeedsDrop>::NEEDS;
11+
- _1 = const <bool as NeedsDrop>::NEEDS;
1212
- switchInt(move _1) -> [0: bb2, otherwise: bb1];
13+
+ _1 = const false;
1314
+ switchInt(const false) -> [0: bb2, otherwise: bb1];
1415
}
1516

tests/mir-opt/const_prop/read_immutable_static.main.GVN.diff

+9-5
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@
1414

1515
bb0: {
1616
StorageLive(_1);
17-
StorageLive(_2);
17+
- StorageLive(_2);
1818
- StorageLive(_3);
19+
+ nop;
1920
+ nop;
2021
_3 = const {ALLOC0: &u8};
21-
_2 = copy (*_3);
22+
- _2 = copy (*_3);
23+
+ _2 = const 2_u8;
2224
StorageLive(_4);
2325
StorageLive(_5);
2426
_5 = const {ALLOC0: &u8};
2527
- _4 = copy (*_5);
26-
+ _4 = copy (*_3);
27-
_1 = Add(move _2, move _4);
28+
- _1 = Add(move _2, move _4);
29+
+ _4 = const 2_u8;
30+
+ _1 = const 4_u8;
2831
StorageDead(_4);
29-
StorageDead(_2);
32+
- StorageDead(_2);
33+
+ nop;
3034
StorageDead(_5);
3135
- StorageDead(_3);
3236
+ nop;

tests/mir-opt/const_prop/read_immutable_static.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ static FOO: u8 = 2;
66
fn main() {
77
// CHECK-LABEL: fn main(
88
// CHECK: debug x => [[x:_.*]];
9-
// Disabled due to <https://github.com/rust-lang/rust/issues/130853>
10-
// COM: CHECK: [[x]] = const 4_u8;
9+
// CHECK: [[x]] = const 4_u8;
1110
let x = FOO + FOO;
1211
}

tests/mir-opt/const_prop/ref_deref.main.GVN.diff

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
StorageLive(_2);
1717
_4 = const main::promoted[0];
1818
_2 = &(*_4);
19-
_1 = copy (*_2);
19+
- _1 = copy (*_2);
20+
+ _1 = const 4_i32;
2021
StorageDead(_2);
2122
_0 = const ();
2223
StorageDead(_1);

tests/mir-opt/const_prop/ref_deref_project.main.GVN.diff

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
StorageLive(_2);
1717
_4 = const main::promoted[0];
1818
_2 = &((*_4).1: i32);
19-
_1 = copy (*_2);
19+
- _1 = copy (*_2);
20+
+ _1 = const 5_i32;
2021
StorageDead(_2);
2122
_0 = const ();
2223
StorageDead(_1);

tests/mir-opt/const_prop/ref_deref_project.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
fn main() {
66
// CHECK-LABEL: fn main(
77
// CHECK: debug a => [[a:_.*]];
8-
// Disabled due to <https://github.com/rust-lang/rust/issues/130853>
9-
// COM: CHECK: [[a]] = const 5_i32;
8+
// CHECK: [[a]] = const 5_i32;
109
let a = *(&(4, 5).1);
1110
}

tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
bb1: {
4242
- _1 = copy (*_2)[_6];
43-
+ _1 = copy (*_2)[1 of 2];
43+
+ _1 = const 2_u32;
4444
StorageDead(_6);
4545
StorageDead(_4);
4646
StorageDead(_2);

tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
bb1: {
4242
- _1 = copy (*_2)[_6];
43-
+ _1 = copy (*_2)[1 of 2];
43+
+ _1 = const 2_u32;
4444
StorageDead(_6);
4545
StorageDead(_4);
4646
StorageDead(_2);

0 commit comments

Comments
 (0)