Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cfae26d

Browse files
committedDec 20, 2024·
Auto merge of rust-lang#132527 - DianQK:gvn-stmt-iter, r=oli-obk
Invalidate all dereferences when encountering non-local assignments 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 5f23ef7 + 199b7f9 commit cfae26d

38 files changed

+506
-549
lines changed
 

‎compiler/rustc_data_structures/src/fx.rs

Lines changed: 2 additions & 0 deletions
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

Lines changed: 95 additions & 85 deletions
Large diffs are not rendered by default.

‎compiler/rustc_mir_transform/src/ssa.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ pub(super) struct SsaLocals {
3232
borrowed_locals: BitSet<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,37 +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(local, AssignedValue::Arg, Location {
163-
block: START_BLOCK,
164-
statement_index: 0,
165-
}),
166-
Set1::One(DefLocation::Assignment(loc)) => {
167-
let bb = &mut basic_blocks[loc.block];
168-
// `loc` must point to a direct assignment to `local`.
169-
let stmt = &mut bb.statements[loc.statement_index];
170-
let StatementKind::Assign(box (target, ref mut rvalue)) = stmt.kind else {
171-
bug!()
172-
};
173-
assert_eq!(target.as_local(), Some(local));
174-
f(local, AssignedValue::Rvalue(rvalue), loc)
175-
}
176-
Set1::One(DefLocation::CallReturn { call, .. }) => {
177-
let bb = &mut basic_blocks[call];
178-
let loc = Location { block: call, statement_index: bb.statements.len() };
179-
f(local, AssignedValue::Terminator, loc)
180-
}
181-
_ => {}
182-
}
183-
}
184-
}
185-
186149
/// Compute the equivalence classes for locals, based on copy statements.
187150
///
188151
/// The returned vector maps each local to the one it copies. In the following case:

‎tests/codegen/clone_as_copy.rs

Lines changed: 0 additions & 2 deletions
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: -O -Cno-prepopulate-passes
53
//@ [DEBUGINFO] compile-flags: -Cdebuginfo=full
64

‎tests/codegen/try_question_mark_nop.rs

Lines changed: 11 additions & 6 deletions
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: %trunc = trunc nuw i32 %0 to i1
20-
// TWENTY-NEXT: %.2 = select i1 %trunc, 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 %.2, 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,

‎tests/coverage/issue-84561.cov-map

Lines changed: 93 additions & 109 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 9 additions & 5 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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.64bit.panic-abort.diff

Lines changed: 1 addition & 1 deletion
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.64bit.panic-unwind.diff

Lines changed: 1 addition & 1 deletion
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.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ fn main() {
88
// CHECK-LABEL: fn main(
99
// CHECK: debug a => [[a:_.*]];
1010
// CHECK: [[slice:_.*]] = copy {{.*}} as &[u32] (PointerCoercion(Unsize, AsCast));
11-
// Disabled due to <https://github.com/rust-lang/rust/issues/130853>
12-
// COM: CHECK: assert(const true,
13-
// COM: CHECK: [[a]] = const 2_u32;
11+
// CHECK: assert(const true,
12+
// CHECK: [[a]] = const 2_u32;
1413
let a = (&[1u32, 2, 3] as &[u32])[1];
1514
}

‎tests/mir-opt/gvn.borrowed.GVN.panic-abort.diff

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
}
1919

2020
bb2: {
21-
_0 = opaque::<T>(copy (*_3)) -> [return: bb3, unwind unreachable];
21+
- _0 = opaque::<T>(copy (*_3)) -> [return: bb3, unwind unreachable];
22+
+ _0 = opaque::<T>(copy _1) -> [return: bb3, unwind unreachable];
2223
}
2324

2425
bb3: {

‎tests/mir-opt/gvn.borrowed.GVN.panic-unwind.diff

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
}
1919

2020
bb2: {
21-
_0 = opaque::<T>(copy (*_3)) -> [return: bb3, unwind continue];
21+
- _0 = opaque::<T>(copy (*_3)) -> [return: bb3, unwind continue];
22+
+ _0 = opaque::<T>(copy _1) -> [return: bb3, unwind continue];
2223
}
2324

2425
bb3: {

‎tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
let mut _3: fn(u8) -> u8;
99
let _5: ();
1010
let mut _6: fn(u8) -> u8;
11-
let mut _9: {closure@$DIR/gvn.rs:615:19: 615:21};
11+
let mut _9: {closure@$DIR/gvn.rs:620:19: 620:21};
1212
let _10: ();
1313
let mut _11: fn();
14-
let mut _13: {closure@$DIR/gvn.rs:615:19: 615:21};
14+
let mut _13: {closure@$DIR/gvn.rs:620:19: 620:21};
1515
let _14: ();
1616
let mut _15: fn();
1717
scope 1 {
1818
debug f => _1;
1919
let _4: fn(u8) -> u8;
2020
scope 2 {
2121
debug g => _4;
22-
let _7: {closure@$DIR/gvn.rs:615:19: 615:21};
22+
let _7: {closure@$DIR/gvn.rs:620:19: 620:21};
2323
scope 3 {
2424
debug closure => _7;
2525
let _8: fn();
@@ -62,16 +62,16 @@
6262
StorageDead(_6);
6363
StorageDead(_5);
6464
- StorageLive(_7);
65-
- _7 = {closure@$DIR/gvn.rs:615:19: 615:21};
65+
- _7 = {closure@$DIR/gvn.rs:620:19: 620:21};
6666
- StorageLive(_8);
6767
+ nop;
68-
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21};
68+
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:620:19: 620:21};
6969
+ nop;
7070
StorageLive(_9);
7171
- _9 = copy _7;
7272
- _8 = move _9 as fn() (PointerCoercion(ClosureFnPointer(Safe), AsCast));
73-
+ _9 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21};
74-
+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21} as fn() (PointerCoercion(ClosureFnPointer(Safe), AsCast));
73+
+ _9 = const ZeroSized: {closure@$DIR/gvn.rs:620:19: 620:21};
74+
+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:620:19: 620:21} as fn() (PointerCoercion(ClosureFnPointer(Safe), AsCast));
7575
StorageDead(_9);
7676
StorageLive(_10);
7777
StorageLive(_11);
@@ -88,8 +88,8 @@
8888
StorageLive(_13);
8989
- _13 = copy _7;
9090
- _12 = move _13 as fn() (PointerCoercion(ClosureFnPointer(Safe), AsCast));
91-
+ _13 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21};
92-
+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21} as fn() (PointerCoercion(ClosureFnPointer(Safe), AsCast));
91+
+ _13 = const ZeroSized: {closure@$DIR/gvn.rs:620:19: 620:21};
92+
+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:620:19: 620:21} as fn() (PointerCoercion(ClosureFnPointer(Safe), AsCast));
9393
StorageDead(_13);
9494
StorageLive(_14);
9595
StorageLive(_15);

‎tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
let mut _3: fn(u8) -> u8;
99
let _5: ();
1010
let mut _6: fn(u8) -> u8;
11-
let mut _9: {closure@$DIR/gvn.rs:615:19: 615:21};
11+
let mut _9: {closure@$DIR/gvn.rs:620:19: 620:21};
1212
let _10: ();
1313
let mut _11: fn();
14-
let mut _13: {closure@$DIR/gvn.rs:615:19: 615:21};
14+
let mut _13: {closure@$DIR/gvn.rs:620:19: 620:21};
1515
let _14: ();
1616
let mut _15: fn();
1717
scope 1 {
1818
debug f => _1;
1919
let _4: fn(u8) -> u8;
2020
scope 2 {
2121
debug g => _4;
22-
let _7: {closure@$DIR/gvn.rs:615:19: 615:21};
22+
let _7: {closure@$DIR/gvn.rs:620:19: 620:21};
2323
scope 3 {
2424
debug closure => _7;
2525
let _8: fn();
@@ -62,16 +62,16 @@
6262
StorageDead(_6);
6363
StorageDead(_5);
6464
- StorageLive(_7);
65-
- _7 = {closure@$DIR/gvn.rs:615:19: 615:21};
65+
- _7 = {closure@$DIR/gvn.rs:620:19: 620:21};
6666
- StorageLive(_8);
6767
+ nop;
68-
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21};
68+
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:620:19: 620:21};
6969
+ nop;
7070
StorageLive(_9);
7171
- _9 = copy _7;
7272
- _8 = move _9 as fn() (PointerCoercion(ClosureFnPointer(Safe), AsCast));
73-
+ _9 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21};
74-
+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21} as fn() (PointerCoercion(ClosureFnPointer(Safe), AsCast));
73+
+ _9 = const ZeroSized: {closure@$DIR/gvn.rs:620:19: 620:21};
74+
+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:620:19: 620:21} as fn() (PointerCoercion(ClosureFnPointer(Safe), AsCast));
7575
StorageDead(_9);
7676
StorageLive(_10);
7777
StorageLive(_11);
@@ -88,8 +88,8 @@
8888
StorageLive(_13);
8989
- _13 = copy _7;
9090
- _12 = move _13 as fn() (PointerCoercion(ClosureFnPointer(Safe), AsCast));
91-
+ _13 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21};
92-
+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615:21} as fn() (PointerCoercion(ClosureFnPointer(Safe), AsCast));
91+
+ _13 = const ZeroSized: {closure@$DIR/gvn.rs:620:19: 620:21};
92+
+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:620:19: 620:21} as fn() (PointerCoercion(ClosureFnPointer(Safe), AsCast));
9393
StorageDead(_13);
9494
StorageLive(_14);
9595
StorageLive(_15);

‎tests/mir-opt/gvn.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,18 @@ fn subexpression_elimination(x: u64, y: u64, mut z: u64) {
100100
opaque((x * y) - y);
101101

102102
// We cannot substitute through an immutable reference.
103-
// (Disabled due to <https://github.com/rust-lang/rust/issues/130853>)
104103
// CHECK: [[ref:_.*]] = &_3;
105104
// CHECK: [[deref:_.*]] = copy (*[[ref]]);
106-
// COM: CHECK: [[addref:_.*]] = Add(copy [[deref]], copy _1);
107-
// COM: CHECK: opaque::<u64>(copy [[addref]])
108-
// COM: CHECK: opaque::<u64>(copy [[addref]])
105+
// CHECK: [[addref:_.*]] = Add(move [[deref]], copy _1);
106+
// CHECK: opaque::<u64>(move [[addref]])
107+
// CHECK: [[deref2:_.*]] = copy (*[[ref]]);
108+
// CHECK: [[addref2:_.*]] = Add(move [[deref2]], copy _1);
109+
// CHECK: opaque::<u64>(move [[addref2]])
109110
let a = &z;
110111
opaque(*a + x);
111112
opaque(*a + x);
112113

113-
// And certainly not through a mutable reference or a pointer.
114+
// But not through a mutable reference or a pointer.
114115
// CHECK: [[mut:_.*]] = &mut _3;
115116
// CHECK: [[addmut:_.*]] = Add(
116117
// CHECK: opaque::<u64>(move [[addmut]])
@@ -142,9 +143,11 @@ fn subexpression_elimination(x: u64, y: u64, mut z: u64) {
142143
// Important: `e` is not `a`!
143144
// CHECK: [[ref2:_.*]] = &_3;
144145
// CHECK: [[deref2:_.*]] = copy (*[[ref2]]);
145-
// COM: CHECK: [[addref2:_.*]] = Add(copy [[deref2]], copy _1);
146-
// COM: CHECK: opaque::<u64>(copy [[addref2]])
147-
// COM: CHECK: opaque::<u64>(copy [[addref2]])
146+
// CHECK: [[addref2:_.*]] = Add(move [[deref2]], copy _1);
147+
// CHECK: opaque::<u64>(move [[addref2]])
148+
// CHECK: [[deref3:_.*]] = copy (*[[ref2]]);
149+
// CHECK: [[addref3:_.*]] = Add(move [[deref3]], copy _1);
150+
// CHECK: opaque::<u64>(move [[addref3]])
148151
let e = &z;
149152
opaque(*e + x);
150153
opaque(*e + x);
@@ -499,8 +502,9 @@ fn dereferences(t: &mut u32, u: &impl Copy, s: &S<u32>) {
499502
// Do not reuse dereferences of `&Freeze`.
500503
// CHECK: [[ref:_.*]] = &(*_1);
501504
// CHECK: [[st7:_.*]] = copy (*[[ref]]);
502-
// COM: CHECK: opaque::<u32>(copy [[st7]])
503-
// COM: CHECK: opaque::<u32>(copy [[st7]])
505+
// CHECK: opaque::<u32>(move [[st7]])
506+
// CHECK: [[st8:_.*]] = copy (*[[ref]]);
507+
// CHECK: opaque::<u32>(move [[st8]])
504508
let z = &*t;
505509
opaque(*z);
506510
opaque(*z);
@@ -519,8 +523,9 @@ fn dereferences(t: &mut u32, u: &impl Copy, s: &S<u32>) {
519523

520524
// `*s` is not Copy, but `(*s).0` is, but we still cannot reuse.
521525
// CHECK: [[st10:_.*]] = copy ((*_3).0: u32);
522-
// COM: CHECK: opaque::<u32>(copy [[st10]])
523-
// COM: CHECK: opaque::<u32>(copy [[st10]])
526+
// CHECK: opaque::<u32>(move [[st10]])
527+
// CHECK: [[st11:_.*]] = copy ((*_3).0: u32);
528+
// CHECK: opaque::<u32>(move [[st11]])
524529
opaque(s.0);
525530
opaque(s.0);
526531
}
@@ -737,7 +742,7 @@ fn borrowed<T: Copy + Freeze>(x: T) {
737742
// CHECK: bb1: {
738743
// CHECK-NEXT: _0 = opaque::<T>(copy _1)
739744
// CHECK: bb2: {
740-
// COM: CHECK-NEXT: _0 = opaque::<T>(copy _1)
745+
// CHECK-NEXT: _0 = opaque::<T>(copy _1)
741746
mir! {
742747
{
743748
let a = x;

‎tests/mir-opt/gvn.slices.GVN.panic-abort.diff

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@
111111
StorageLive(_7);
112112
StorageLive(_8);
113113
- StorageLive(_9);
114+
- StorageLive(_10);
115+
+ nop;
114116
+ nop;
115-
StorageLive(_10);
116117
StorageLive(_11);
117118
_11 = &(*_1);
118119
_10 = core::str::<impl str>::as_ptr(move _11) -> [return: bb3, unwind unreachable];
@@ -122,8 +123,9 @@
122123
StorageDead(_11);
123124
_9 = &_10;
124125
- StorageLive(_12);
126+
- StorageLive(_13);
127+
+ nop;
125128
+ nop;
126-
StorageLive(_13);
127129
StorageLive(_14);
128130
- _14 = &(*_4);
129131
+ _14 = &(*_1);
@@ -148,11 +150,12 @@
148150
StorageLive(_17);
149151
StorageLive(_18);
150152
- _18 = copy (*_15);
151-
+ _18 = copy (*_9);
153+
+ _18 = copy _10;
152154
StorageLive(_19);
153155
- _19 = copy (*_16);
154-
+ _19 = copy (*_12);
155-
_17 = Eq(move _18, move _19);
156+
- _17 = Eq(move _18, move _19);
157+
+ _19 = copy _13;
158+
+ _17 = Eq(copy _10, copy _13);
156159
switchInt(move _17) -> [0: bb6, otherwise: bb5];
157160
}
158161

@@ -163,8 +166,10 @@
163166
StorageDead(_17);
164167
StorageDead(_16);
165168
StorageDead(_15);
166-
StorageDead(_13);
167-
StorageDead(_10);
169+
- StorageDead(_13);
170+
- StorageDead(_10);
171+
+ nop;
172+
+ nop;
168173
StorageDead(_8);
169174
StorageDead(_7);
170175
- StorageLive(_29);
@@ -213,8 +218,9 @@
213218
StorageLive(_33);
214219
StorageLive(_34);
215220
- StorageLive(_35);
221+
- StorageLive(_36);
222+
+ nop;
216223
+ nop;
217-
StorageLive(_36);
218224
StorageLive(_37);
219225
_37 = &(*_1);
220226
_36 = core::str::<impl str>::as_ptr(move _37) -> [return: bb8, unwind unreachable];
@@ -224,8 +230,9 @@
224230
StorageDead(_37);
225231
_35 = &_36;
226232
- StorageLive(_38);
233+
- StorageLive(_39);
234+
+ nop;
227235
+ nop;
228-
StorageLive(_39);
229236
StorageLive(_40);
230237
_40 = &(*_29);
231238
_39 = core::slice::<impl [u8]>::as_ptr(move _40) -> [return: bb9, unwind unreachable];
@@ -249,11 +256,12 @@
249256
StorageLive(_43);
250257
StorageLive(_44);
251258
- _44 = copy (*_41);
252-
+ _44 = copy (*_35);
259+
+ _44 = copy _36;
253260
StorageLive(_45);
254261
- _45 = copy (*_42);
255-
+ _45 = copy (*_38);
256-
_43 = Eq(move _44, move _45);
262+
- _43 = Eq(move _44, move _45);
263+
+ _45 = copy _39;
264+
+ _43 = Eq(copy _36, copy _39);
257265
switchInt(move _43) -> [0: bb11, otherwise: bb10];
258266
}
259267

@@ -264,8 +272,10 @@
264272
StorageDead(_43);
265273
StorageDead(_42);
266274
StorageDead(_41);
267-
StorageDead(_39);
268-
StorageDead(_36);
275+
- StorageDead(_39);
276+
- StorageDead(_36);
277+
+ nop;
278+
+ nop;
269279
StorageDead(_34);
270280
StorageDead(_33);
271281
_0 = const ();

‎tests/mir-opt/gvn.slices.GVN.panic-unwind.diff

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@
111111
StorageLive(_7);
112112
StorageLive(_8);
113113
- StorageLive(_9);
114+
- StorageLive(_10);
115+
+ nop;
114116
+ nop;
115-
StorageLive(_10);
116117
StorageLive(_11);
117118
_11 = &(*_1);
118119
_10 = core::str::<impl str>::as_ptr(move _11) -> [return: bb3, unwind continue];
@@ -122,8 +123,9 @@
122123
StorageDead(_11);
123124
_9 = &_10;
124125
- StorageLive(_12);
126+
- StorageLive(_13);
127+
+ nop;
125128
+ nop;
126-
StorageLive(_13);
127129
StorageLive(_14);
128130
- _14 = &(*_4);
129131
+ _14 = &(*_1);
@@ -148,11 +150,12 @@
148150
StorageLive(_17);
149151
StorageLive(_18);
150152
- _18 = copy (*_15);
151-
+ _18 = copy (*_9);
153+
+ _18 = copy _10;
152154
StorageLive(_19);
153155
- _19 = copy (*_16);
154-
+ _19 = copy (*_12);
155-
_17 = Eq(move _18, move _19);
156+
- _17 = Eq(move _18, move _19);
157+
+ _19 = copy _13;
158+
+ _17 = Eq(copy _10, copy _13);
156159
switchInt(move _17) -> [0: bb6, otherwise: bb5];
157160
}
158161

@@ -163,8 +166,10 @@
163166
StorageDead(_17);
164167
StorageDead(_16);
165168
StorageDead(_15);
166-
StorageDead(_13);
167-
StorageDead(_10);
169+
- StorageDead(_13);
170+
- StorageDead(_10);
171+
+ nop;
172+
+ nop;
168173
StorageDead(_8);
169174
StorageDead(_7);
170175
- StorageLive(_29);
@@ -213,8 +218,9 @@
213218
StorageLive(_33);
214219
StorageLive(_34);
215220
- StorageLive(_35);
221+
- StorageLive(_36);
222+
+ nop;
216223
+ nop;
217-
StorageLive(_36);
218224
StorageLive(_37);
219225
_37 = &(*_1);
220226
_36 = core::str::<impl str>::as_ptr(move _37) -> [return: bb8, unwind continue];
@@ -224,8 +230,9 @@
224230
StorageDead(_37);
225231
_35 = &_36;
226232
- StorageLive(_38);
233+
- StorageLive(_39);
234+
+ nop;
227235
+ nop;
228-
StorageLive(_39);
229236
StorageLive(_40);
230237
_40 = &(*_29);
231238
_39 = core::slice::<impl [u8]>::as_ptr(move _40) -> [return: bb9, unwind continue];
@@ -249,11 +256,12 @@
249256
StorageLive(_43);
250257
StorageLive(_44);
251258
- _44 = copy (*_41);
252-
+ _44 = copy (*_35);
259+
+ _44 = copy _36;
253260
StorageLive(_45);
254261
- _45 = copy (*_42);
255-
+ _45 = copy (*_38);
256-
_43 = Eq(move _44, move _45);
262+
- _43 = Eq(move _44, move _45);
263+
+ _45 = copy _39;
264+
+ _43 = Eq(copy _36, copy _39);
257265
switchInt(move _43) -> [0: bb11, otherwise: bb10];
258266
}
259267

@@ -264,8 +272,10 @@
264272
StorageDead(_43);
265273
StorageDead(_42);
266274
StorageDead(_41);
267-
StorageDead(_39);
268-
StorageDead(_36);
275+
- StorageDead(_39);
276+
- StorageDead(_36);
277+
+ nop;
278+
+ nop;
269279
StorageDead(_34);
270280
StorageDead(_33);
271281
_0 = const ();

‎tests/mir-opt/gvn_clone.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@ compile-flags: -Zunsound-mir-opts
2-
// FIXME: see <https://github.com/rust-lang/rust/issues/132353>
31
//@ test-mir-pass: GVN
42
//@ compile-flags: -Zmir-enable-passes=+InstSimplify-before-inline
53

‎tests/mir-opt/gvn_clone.{impl#0}-clone.GVN.diff

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
- // MIR for `<impl at $DIR/gvn_clone.rs:14:10: 14:15>::clone` before GVN
2-
+ // MIR for `<impl at $DIR/gvn_clone.rs:14:10: 14:15>::clone` after GVN
1+
- // MIR for `<impl at $DIR/gvn_clone.rs:12:10: 12:15>::clone` before GVN
2+
+ // MIR for `<impl at $DIR/gvn_clone.rs:12:10: 12:15>::clone` after GVN
33

4-
fn <impl at $DIR/gvn_clone.rs:14:10: 14:15>::clone(_1: &AllCopy) -> AllCopy {
4+
fn <impl at $DIR/gvn_clone.rs:12:10: 12:15>::clone(_1: &AllCopy) -> AllCopy {
55
debug self => _1;
66
let mut _0: AllCopy;
77
let mut _2: i32;

‎tests/mir-opt/gvn_copy_aggregate.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@ compile-flags: -Zunsound-mir-opts
2-
// FIXME: see <https://github.com/rust-lang/rust/issues/132353.
31
//@ test-mir-pass: GVN
42
//@ compile-flags: -Cpanic=abort
53

‎tests/mir-opt/gvn_uninhabited.f.GVN.panic-abort.diff

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
StorageLive(_3);
1818
_5 = const f::promoted[0];
1919
_3 = &(*_5);
20-
_2 = copy ((*_3).1: E);
21-
- StorageLive(_1);
22-
+ nop;
23-
_1 = copy ((_2 as A).1: u32);
20+
- _2 = copy ((*_3).1: E);
21+
+ _2 = copy ((*_5).1: E);
22+
StorageLive(_1);
23+
- _1 = copy ((_2 as A).1: u32);
24+
+ _1 = const 0_u32;
2425
StorageDead(_3);
2526
StorageDead(_2);
26-
_0 = copy _1;
27-
- StorageDead(_1);
28-
+ nop;
27+
- _0 = copy _1;
28+
+ _0 = const 0_u32;
29+
StorageDead(_1);
2930
return;
3031
}
3132
}

‎tests/mir-opt/gvn_uninhabited.f.GVN.panic-unwind.diff

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
StorageLive(_3);
1818
_5 = const f::promoted[0];
1919
_3 = &(*_5);
20-
_2 = copy ((*_3).1: E);
21-
- StorageLive(_1);
22-
+ nop;
23-
_1 = copy ((_2 as A).1: u32);
20+
- _2 = copy ((*_3).1: E);
21+
+ _2 = copy ((*_5).1: E);
22+
StorageLive(_1);
23+
- _1 = copy ((_2 as A).1: u32);
24+
+ _1 = const 0_u32;
2425
StorageDead(_3);
2526
StorageDead(_2);
26-
_0 = copy _1;
27-
- StorageDead(_1);
28-
+ nop;
27+
- _0 = copy _1;
28+
+ _0 = const 0_u32;
29+
StorageDead(_1);
2930
return;
3031
}
3132
}

‎tests/mir-opt/pre-codegen/clone_as_copy.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@ compile-flags: -Zunsound-mir-opts
2-
// FIXME: see <https://github.com/rust-lang/rust/issues/132353>
31
//@ compile-flags: -Cdebuginfo=full
42

53
// Check if we have transformed the nested clone to the copy in the complete pipeline.

‎tests/mir-opt/pre-codegen/deref_nested_borrows.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//! Regression test for <https://github.com/rust-lang/rust/issues/130853>
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32

43
fn src(x: &&u8) -> bool {

‎tests/mir-opt/pre-codegen/no_inlined_clone.{impl#0}-clone.PreCodegen.after.mir

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
fn <impl at $DIR/no_inlined_clone.rs:9:10: 9:15>::clone(_1: &Foo) -> Foo {
44
debug self => _1;
55
let mut _0: Foo;
6-
let mut _2: i32;
76

87
bb0: {
9-
StorageLive(_2);
10-
_2 = copy ((*_1).0: i32);
11-
_0 = Foo { a: move _2 };
12-
StorageDead(_2);
8+
_0 = copy (*_1);
139
return;
1410
}
1511
}

‎tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir

Lines changed: 110 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -4,200 +4,182 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:7:25: 7:39}, _2
44
let mut _0: bool;
55
let mut _3: &(usize, usize, usize, usize);
66
let _4: &usize;
7-
let mut _5: &(usize, usize, usize, usize);
7+
let _5: &usize;
88
let _6: &usize;
9-
let mut _7: &(usize, usize, usize, usize);
10-
let _8: &usize;
11-
let mut _9: &(usize, usize, usize, usize);
12-
let _10: &usize;
13-
let mut _11: &&usize;
14-
let _12: &usize;
15-
let mut _13: &&usize;
16-
let mut _16: bool;
17-
let mut _17: &&usize;
18-
let _18: &usize;
19-
let mut _19: &&usize;
20-
let mut _22: bool;
21-
let mut _23: &&usize;
22-
let _24: &usize;
23-
let mut _25: &&usize;
24-
let mut _28: bool;
25-
let mut _29: &&usize;
26-
let _30: &usize;
27-
let mut _31: &&usize;
9+
let _7: &usize;
10+
let mut _8: &&usize;
11+
let _9: &usize;
12+
let mut _10: &&usize;
13+
let mut _13: bool;
14+
let mut _14: &&usize;
15+
let _15: &usize;
16+
let mut _16: &&usize;
17+
let mut _19: bool;
18+
let mut _20: &&usize;
19+
let _21: &usize;
20+
let mut _22: &&usize;
21+
let mut _23: bool;
22+
let mut _24: &&usize;
23+
let _25: &usize;
24+
let mut _26: &&usize;
2825
scope 1 {
2926
debug a => _4;
30-
debug b => _6;
31-
debug c => _8;
32-
debug d => _10;
27+
debug b => _5;
28+
debug c => _6;
29+
debug d => _7;
3330
scope 2 (inlined std::cmp::impls::<impl PartialOrd for &usize>::le) {
34-
debug self => _11;
35-
debug other => _13;
31+
debug self => _8;
32+
debug other => _10;
3633
scope 3 (inlined std::cmp::impls::<impl PartialOrd for usize>::le) {
3734
debug self => _4;
38-
debug other => _8;
39-
let mut _14: usize;
40-
let mut _15: usize;
35+
debug other => _6;
36+
let mut _11: usize;
37+
let mut _12: usize;
4138
}
4239
}
4340
scope 4 (inlined std::cmp::impls::<impl PartialOrd for &usize>::le) {
44-
debug self => _17;
45-
debug other => _19;
41+
debug self => _14;
42+
debug other => _16;
4643
scope 5 (inlined std::cmp::impls::<impl PartialOrd for usize>::le) {
47-
debug self => _10;
48-
debug other => _6;
49-
let mut _20: usize;
50-
let mut _21: usize;
44+
debug self => _7;
45+
debug other => _5;
46+
let mut _17: usize;
47+
let mut _18: usize;
5148
}
5249
}
5350
scope 6 (inlined std::cmp::impls::<impl PartialOrd for &usize>::le) {
54-
debug self => _23;
55-
debug other => _25;
51+
debug self => _20;
52+
debug other => _22;
5653
scope 7 (inlined std::cmp::impls::<impl PartialOrd for usize>::le) {
57-
debug self => _8;
54+
debug self => _6;
5855
debug other => _4;
59-
let mut _26: usize;
60-
let mut _27: usize;
6156
}
6257
}
6358
scope 8 (inlined std::cmp::impls::<impl PartialOrd for &usize>::le) {
64-
debug self => _29;
65-
debug other => _31;
59+
debug self => _24;
60+
debug other => _26;
6661
scope 9 (inlined std::cmp::impls::<impl PartialOrd for usize>::le) {
67-
debug self => _6;
68-
debug other => _10;
69-
let mut _32: usize;
70-
let mut _33: usize;
62+
debug self => _5;
63+
debug other => _7;
64+
let mut _27: usize;
65+
let mut _28: usize;
7166
}
7267
}
7368
}
7469

7570
bb0: {
7671
_3 = copy (*_2);
7772
_4 = &((*_3).0: usize);
78-
_5 = copy (*_2);
79-
_6 = &((*_5).1: usize);
80-
_7 = copy (*_2);
81-
_8 = &((*_7).2: usize);
82-
_9 = copy (*_2);
83-
_10 = &((*_9).3: usize);
84-
StorageLive(_16);
85-
StorageLive(_11);
86-
_11 = &_4;
73+
_5 = &((*_3).1: usize);
74+
_6 = &((*_3).2: usize);
75+
_7 = &((*_3).3: usize);
8776
StorageLive(_13);
88-
StorageLive(_12);
89-
_12 = copy _8;
90-
_13 = &_12;
91-
StorageLive(_14);
92-
_14 = copy ((*_3).0: usize);
93-
StorageLive(_15);
94-
_15 = copy ((*_7).2: usize);
95-
_16 = Le(move _14, move _15);
96-
StorageDead(_15);
97-
StorageDead(_14);
98-
switchInt(move _16) -> [0: bb1, otherwise: bb2];
77+
StorageLive(_8);
78+
_8 = &_4;
79+
StorageLive(_10);
80+
StorageLive(_9);
81+
_9 = copy _6;
82+
_10 = &_9;
83+
_11 = copy ((*_3).0: usize);
84+
_12 = copy ((*_3).2: usize);
85+
_13 = Le(copy _11, copy _12);
86+
switchInt(move _13) -> [0: bb1, otherwise: bb2];
9987
}
10088

10189
bb1: {
102-
StorageDead(_12);
103-
StorageDead(_13);
104-
StorageDead(_11);
90+
StorageDead(_9);
91+
StorageDead(_10);
92+
StorageDead(_8);
10593
goto -> bb4;
10694
}
10795

10896
bb2: {
109-
StorageDead(_12);
110-
StorageDead(_13);
111-
StorageDead(_11);
112-
StorageLive(_22);
113-
StorageLive(_17);
114-
_17 = &_10;
97+
StorageDead(_9);
98+
StorageDead(_10);
99+
StorageDead(_8);
115100
StorageLive(_19);
101+
StorageLive(_14);
102+
_14 = &_7;
103+
StorageLive(_16);
104+
StorageLive(_15);
105+
_15 = copy _5;
106+
_16 = &_15;
107+
StorageLive(_17);
108+
_17 = copy ((*_3).3: usize);
116109
StorageLive(_18);
117-
_18 = copy _6;
118-
_19 = &_18;
119-
StorageLive(_20);
120-
_20 = copy ((*_9).3: usize);
121-
StorageLive(_21);
122-
_21 = copy ((*_5).1: usize);
123-
_22 = Le(move _20, move _21);
124-
StorageDead(_21);
125-
StorageDead(_20);
126-
switchInt(move _22) -> [0: bb3, otherwise: bb8];
110+
_18 = copy ((*_3).1: usize);
111+
_19 = Le(move _17, move _18);
112+
StorageDead(_18);
113+
StorageDead(_17);
114+
switchInt(move _19) -> [0: bb3, otherwise: bb8];
127115
}
128116

129117
bb3: {
130-
StorageDead(_18);
131-
StorageDead(_19);
132-
StorageDead(_17);
118+
StorageDead(_15);
119+
StorageDead(_16);
120+
StorageDead(_14);
133121
goto -> bb4;
134122
}
135123

136124
bb4: {
137-
StorageLive(_28);
138125
StorageLive(_23);
139-
_23 = &_8;
140-
StorageLive(_25);
141-
StorageLive(_24);
142-
_24 = copy _4;
143-
_25 = &_24;
144-
StorageLive(_26);
145-
_26 = copy ((*_7).2: usize);
146-
StorageLive(_27);
147-
_27 = copy ((*_3).0: usize);
148-
_28 = Le(move _26, move _27);
149-
StorageDead(_27);
150-
StorageDead(_26);
151-
switchInt(move _28) -> [0: bb5, otherwise: bb6];
126+
StorageLive(_20);
127+
_20 = &_6;
128+
StorageLive(_22);
129+
StorageLive(_21);
130+
_21 = copy _4;
131+
_22 = &_21;
132+
_23 = Le(copy _12, copy _11);
133+
switchInt(move _23) -> [0: bb5, otherwise: bb6];
152134
}
153135

154136
bb5: {
155-
StorageDead(_24);
156-
StorageDead(_25);
157-
StorageDead(_23);
137+
StorageDead(_21);
138+
StorageDead(_22);
139+
StorageDead(_20);
158140
_0 = const false;
159141
goto -> bb7;
160142
}
161143

162144
bb6: {
163-
StorageDead(_24);
145+
StorageDead(_21);
146+
StorageDead(_22);
147+
StorageDead(_20);
148+
StorageLive(_24);
149+
_24 = &_5;
150+
StorageLive(_26);
151+
StorageLive(_25);
152+
_25 = copy _7;
153+
_26 = &_25;
154+
StorageLive(_27);
155+
_27 = copy ((*_3).1: usize);
156+
StorageLive(_28);
157+
_28 = copy ((*_3).3: usize);
158+
_0 = Le(move _27, move _28);
159+
StorageDead(_28);
160+
StorageDead(_27);
164161
StorageDead(_25);
165-
StorageDead(_23);
166-
StorageLive(_29);
167-
_29 = &_6;
168-
StorageLive(_31);
169-
StorageLive(_30);
170-
_30 = copy _10;
171-
_31 = &_30;
172-
StorageLive(_32);
173-
_32 = copy ((*_5).1: usize);
174-
StorageLive(_33);
175-
_33 = copy ((*_9).3: usize);
176-
_0 = Le(move _32, move _33);
177-
StorageDead(_33);
178-
StorageDead(_32);
179-
StorageDead(_30);
180-
StorageDead(_31);
181-
StorageDead(_29);
162+
StorageDead(_26);
163+
StorageDead(_24);
182164
goto -> bb7;
183165
}
184166

185167
bb7: {
186-
StorageDead(_28);
168+
StorageDead(_23);
187169
goto -> bb9;
188170
}
189171

190172
bb8: {
191-
StorageDead(_18);
192-
StorageDead(_19);
193-
StorageDead(_17);
173+
StorageDead(_15);
174+
StorageDead(_16);
175+
StorageDead(_14);
194176
_0 = const true;
195177
goto -> bb9;
196178
}
197179

198180
bb9: {
199-
StorageDead(_22);
200-
StorageDead(_16);
181+
StorageDead(_19);
182+
StorageDead(_13);
201183
return;
202184
}
203185
}

‎tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,40 @@ fn variant_b::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:11:25: 11:41},
44
let mut _0: bool;
55
let mut _3: &(usize, usize, usize, usize);
66
let _4: usize;
7-
let mut _5: &(usize, usize, usize, usize);
7+
let _5: usize;
88
let _6: usize;
9-
let mut _7: &(usize, usize, usize, usize);
10-
let _8: usize;
11-
let mut _9: &(usize, usize, usize, usize);
12-
let _10: usize;
13-
let mut _11: bool;
14-
let mut _12: bool;
15-
let mut _13: bool;
9+
let _7: usize;
10+
let mut _8: bool;
11+
let mut _9: bool;
12+
let mut _10: bool;
1613
scope 1 {
1714
debug a => _4;
18-
debug b => _6;
19-
debug c => _8;
20-
debug d => _10;
15+
debug b => _5;
16+
debug c => _6;
17+
debug d => _7;
2118
}
2219

2320
bb0: {
2421
_3 = copy (*_2);
2522
_4 = copy ((*_3).0: usize);
26-
_5 = copy (*_2);
27-
_6 = copy ((*_5).1: usize);
28-
_7 = copy (*_2);
29-
_8 = copy ((*_7).2: usize);
30-
_9 = copy (*_2);
31-
_10 = copy ((*_9).3: usize);
32-
StorageLive(_11);
33-
_11 = Le(copy _4, copy _8);
34-
switchInt(move _11) -> [0: bb2, otherwise: bb1];
23+
_5 = copy ((*_3).1: usize);
24+
_6 = copy ((*_3).2: usize);
25+
_7 = copy ((*_3).3: usize);
26+
StorageLive(_8);
27+
_8 = Le(copy _4, copy _6);
28+
switchInt(move _8) -> [0: bb2, otherwise: bb1];
3529
}
3630

3731
bb1: {
38-
StorageLive(_12);
39-
_12 = Le(copy _10, copy _6);
40-
switchInt(move _12) -> [0: bb2, otherwise: bb6];
32+
StorageLive(_9);
33+
_9 = Le(copy _7, copy _5);
34+
switchInt(move _9) -> [0: bb2, otherwise: bb6];
4135
}
4236

4337
bb2: {
44-
StorageLive(_13);
45-
_13 = Le(copy _8, copy _4);
46-
switchInt(move _13) -> [0: bb3, otherwise: bb4];
38+
StorageLive(_10);
39+
_10 = Le(copy _6, copy _4);
40+
switchInt(move _10) -> [0: bb3, otherwise: bb4];
4741
}
4842

4943
bb3: {
@@ -52,12 +46,12 @@ fn variant_b::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:11:25: 11:41},
5246
}
5347

5448
bb4: {
55-
_0 = Le(copy _6, copy _10);
49+
_0 = Le(copy _5, copy _7);
5650
goto -> bb5;
5751
}
5852

5953
bb5: {
60-
StorageDead(_13);
54+
StorageDead(_10);
6155
goto -> bb7;
6256
}
6357

@@ -67,8 +61,8 @@ fn variant_b::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:11:25: 11:41},
6761
}
6862

6963
bb7: {
70-
StorageDead(_12);
71-
StorageDead(_11);
64+
StorageDead(_9);
65+
StorageDead(_8);
7266
return;
7367
}
7468
}

‎tests/mir-opt/pre-codegen/try_identity.old.PreCodegen.after.mir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ fn old(_1: Result<T, E>) -> Result<T, E> {
1919
}
2020

2121
bb1: {
22-
_3 = move ((_1 as Ok).0: T);
23-
_0 = Result::<T, E>::Ok(copy _3);
22+
_3 = copy ((_1 as Ok).0: T);
23+
_0 = copy _1;
2424
goto -> bb3;
2525
}
2626

2727
bb2: {
28-
_4 = move ((_1 as Err).0: E);
29-
_0 = Result::<T, E>::Err(copy _4);
28+
_4 = copy ((_1 as Err).0: E);
29+
_0 = copy _1;
3030
goto -> bb3;
3131
}
3232

‎tests/mir-opt/simplify_aggregate_to_copy_miscompile.foo.GVN.diff

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,62 +6,52 @@
66
let mut _0: std::option::Option<i32>;
77
let mut _2: &std::option::Option<i32>;
88
let mut _3: &std::option::Option<i32>;
9-
let _4: &&mut std::option::Option<i32>;
10-
let mut _5: isize;
11-
let mut _7: !;
12-
let mut _8: std::option::Option<i32>;
13-
let mut _9: i32;
14-
let mut _10: !;
15-
let mut _11: &mut std::option::Option<i32>;
9+
let mut _4: isize;
10+
let mut _6: !;
11+
let mut _7: std::option::Option<i32>;
12+
let mut _8: i32;
13+
let mut _9: !;
1614
scope 1 {
17-
debug col => _6;
18-
let _6: i32;
15+
debug col => _5;
16+
let _5: i32;
1917
}
2018

2119
bb0: {
22-
- StorageLive(_2);
23-
+ nop;
20+
StorageLive(_2);
2421
StorageLive(_3);
25-
StorageLive(_4);
26-
_4 = &_1;
27-
- _11 = deref_copy (*_4);
28-
- _3 = &(*_11);
29-
+ _11 = copy _1;
30-
+ _3 = &(*_1);
22+
_3 = &(*_1);
3123
_2 = get(move _3) -> [return: bb1, unwind unreachable];
3224
}
3325

3426
bb1: {
3527
StorageDead(_3);
36-
_5 = discriminant((*_2));
37-
switchInt(move _5) -> [1: bb2, otherwise: bb3];
28+
_4 = discriminant((*_2));
29+
switchInt(move _4) -> [1: bb2, otherwise: bb3];
3830
}
3931

4032
bb2: {
41-
- StorageLive(_6);
33+
- StorageLive(_5);
4234
+ nop;
43-
_6 = copy (((*_2) as Some).0: i32);
44-
StorageLive(_8);
45-
- _8 = Option::<i32>::None;
46-
- (*_1) = move _8;
47-
+ _8 = const Option::<i32>::None;
35+
_5 = copy (((*_2) as Some).0: i32);
36+
StorageLive(_7);
37+
- _7 = Option::<i32>::None;
38+
- (*_1) = move _7;
39+
+ _7 = const Option::<i32>::None;
4840
+ (*_1) = const Option::<i32>::None;
41+
StorageDead(_7);
42+
StorageLive(_8);
43+
_8 = copy _5;
44+
- _0 = Option::<i32>::Some(move _8);
45+
+ _0 = Option::<i32>::Some(copy _5);
4946
StorageDead(_8);
50-
StorageLive(_9);
51-
_9 = copy _6;
52-
- _0 = Option::<i32>::Some(move _9);
53-
+ _0 = copy (*_2);
54-
StorageDead(_9);
55-
- StorageDead(_6);
56-
+ nop;
57-
StorageDead(_4);
58-
- StorageDead(_2);
47+
- StorageDead(_5);
5948
+ nop;
49+
StorageDead(_2);
6050
return;
6151
}
6252

6353
bb3: {
64-
StorageLive(_10);
54+
StorageLive(_9);
6555
unreachable;
6656
}
6757
+ }

‎tests/mir-opt/simplify_aggregate_to_copy_miscompile.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@
77
//! This test demonstrates the behavior, and should be adjusted or removed when fixing and relanding
88
//! the mir-opt.
99
#![crate_type = "lib"]
10-
// skip-filecheck
11-
//@ compile-flags: -O -Zunsound-mir-opts
1210
//@ test-mir-pass: GVN
1311
#![allow(internal_features)]
1412
#![feature(rustc_attrs, core_intrinsics)]
1513

1614
// EMIT_MIR simplify_aggregate_to_copy_miscompile.foo.GVN.diff
1715
#[no_mangle]
1816
fn foo(v: &mut Option<i32>) -> Option<i32> {
19-
if let &Some(col) = get(&v) {
17+
// CHECK-LABEL: fn foo(
18+
// CHECK-SAME: [[v:_.*]]: &mut Option<i32>
19+
// CHECK: [[v_alias_1:_.*]] = &(*_1)
20+
// CHECK-NEXT: [[v_alias_2:_.*]] = get(move [[v_alias_1]])
21+
// CHECK: (*[[v]]) = const Option::<i32>::None;
22+
// CHECK-NOT: _0 = copy (*[[v_alias_2]])
23+
// CHECK: _0 = Option::<i32>::Some
24+
// CHECK-NOT: _0 = copy (*[[v_alias_2]])
25+
if let &Some(col) = get(v) {
2026
*v = None;
2127
return Some(col);
2228
} else {

0 commit comments

Comments
 (0)
This repository has been archived.