Skip to content

Commit 6b6a867

Browse files
committedNov 27, 2024
Auto merge of #133474 - RalfJung:gvn-miscompile, r=compiler-errors
Do not unify dereferences of shared borrows in GVN Repost of #132461, the last commit applies my suggestions. Fixes #130853
·
1.88.01.85.0
2 parents c322cd5 + 906f66f commit 6b6a867

33 files changed

+614
-482
lines changed
 

‎compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,9 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
638638
let proj = match proj {
639639
ProjectionElem::Deref => {
640640
let ty = place.ty(self.local_decls, self.tcx).ty;
641-
if let Some(Mutability::Not) = ty.ref_mutability()
641+
// unsound: https://github.com/rust-lang/rust/issues/130853
642+
if self.tcx.sess.opts.unstable_opts.unsound_mir_opts
643+
&& let Some(Mutability::Not) = ty.ref_mutability()
642644
&& let Some(pointee_ty) = ty.builtin_deref(true)
643645
&& pointee_ty.is_freeze(self.tcx, self.typing_env())
644646
{

‎tests/coverage/closure.cov-map

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,19 @@ Number of file 0 mappings: 6
140140
- Code(Counter(0)) at (prev + 2, 9) to (start + 0, 10)
141141
Highest counter ID seen: c1
142142

143-
Function name: closure::main::{closure#18} (unused)
144-
Raw bytes (24): 0x[01, 01, 00, 04, 00, 19, 0d, 02, 1c, 00, 02, 1d, 02, 12, 00, 02, 11, 00, 12, 00, 01, 11, 01, 0e]
143+
Function name: closure::main::{closure#18}
144+
Raw bytes (26): 0x[01, 01, 01, 01, 05, 04, 01, 19, 0d, 02, 1c, 05, 02, 1d, 02, 12, 02, 02, 11, 00, 12, 01, 01, 11, 01, 0e]
145145
Number of files: 1
146146
- file 0 => global file 1
147-
Number of expressions: 0
147+
Number of expressions: 1
148+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
148149
Number of file 0 mappings: 4
149-
- Code(Zero) at (prev + 25, 13) to (start + 2, 28)
150-
- Code(Zero) at (prev + 2, 29) to (start + 2, 18)
151-
- Code(Zero) at (prev + 2, 17) to (start + 0, 18)
152-
- Code(Zero) at (prev + 1, 17) to (start + 1, 14)
153-
Highest counter ID seen: (none)
150+
- Code(Counter(0)) at (prev + 25, 13) to (start + 2, 28)
151+
- Code(Counter(1)) at (prev + 2, 29) to (start + 2, 18)
152+
- Code(Expression(0, Sub)) at (prev + 2, 17) to (start + 0, 18)
153+
= (c0 - c1)
154+
- Code(Counter(0)) at (prev + 1, 17) to (start + 1, 14)
155+
Highest counter ID seen: c1
154156

155157
Function name: closure::main::{closure#19}
156158
Raw bytes (26): 0x[01, 01, 01, 01, 05, 04, 01, 43, 0d, 02, 1c, 05, 02, 1d, 02, 12, 02, 02, 11, 00, 12, 01, 01, 11, 01, 0e]

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

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

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,19 @@
1414

1515
bb0: {
1616
StorageLive(_1);
17-
- StorageLive(_2);
17+
StorageLive(_2);
1818
- StorageLive(_3);
19-
+ nop;
2019
+ nop;
2120
_3 = const {ALLOC0: &u8};
22-
- _2 = copy (*_3);
23-
+ _2 = const 2_u8;
21+
_2 = copy (*_3);
2422
StorageLive(_4);
2523
StorageLive(_5);
2624
_5 = const {ALLOC0: &u8};
2725
- _4 = copy (*_5);
28-
- _1 = Add(move _2, move _4);
29-
+ _4 = const 2_u8;
30-
+ _1 = const 4_u8;
26+
+ _4 = copy (*_3);
27+
_1 = Add(move _2, move _4);
3128
StorageDead(_4);
32-
- StorageDead(_2);
33-
+ nop;
29+
StorageDead(_2);
3430
StorageDead(_5);
3531
- StorageDead(_3);
3632
+ nop;

‎tests/mir-opt/const_prop/read_immutable_static.rs

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

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

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

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

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

‎tests/mir-opt/const_prop/ref_deref_project.rs

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

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,16 @@
3030
StorageDead(_3);
3131
StorageLive(_6);
3232
_6 = const 1_usize;
33-
- _7 = Len((*_2));
33+
_7 = Len((*_2));
3434
- _8 = Lt(copy _6, copy _7);
3535
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, copy _6) -> [success: bb1, unwind unreachable];
36-
+ _7 = const 3_usize;
37-
+ _8 = const true;
38-
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb1, unwind unreachable];
36+
+ _8 = Lt(const 1_usize, copy _7);
37+
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 1_usize) -> [success: bb1, unwind unreachable];
3938
}
4039

4140
bb1: {
4241
- _1 = copy (*_2)[_6];
43-
+ _1 = const 2_u32;
42+
+ _1 = copy (*_2)[1 of 2];
4443
StorageDead(_6);
4544
StorageDead(_4);
4645
StorageDead(_2);

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,16 @@
3030
StorageDead(_3);
3131
StorageLive(_6);
3232
_6 = const 1_usize;
33-
- _7 = Len((*_2));
33+
_7 = Len((*_2));
3434
- _8 = Lt(copy _6, copy _7);
3535
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, copy _6) -> [success: bb1, unwind continue];
36-
+ _7 = const 3_usize;
37-
+ _8 = const true;
38-
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb1, unwind continue];
36+
+ _8 = Lt(const 1_usize, copy _7);
37+
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 1_usize) -> [success: bb1, unwind continue];
3938
}
4039

4140
bb1: {
4241
- _1 = copy (*_2)[_6];
43-
+ _1 = const 2_u32;
42+
+ _1 = copy (*_2)[1 of 2];
4443
StorageDead(_6);
4544
StorageDead(_4);
4645
StorageDead(_2);

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,16 @@
3030
StorageDead(_3);
3131
StorageLive(_6);
3232
_6 = const 1_usize;
33-
- _7 = Len((*_2));
33+
_7 = Len((*_2));
3434
- _8 = Lt(copy _6, copy _7);
3535
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, copy _6) -> [success: bb1, unwind unreachable];
36-
+ _7 = const 3_usize;
37-
+ _8 = const true;
38-
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb1, unwind unreachable];
36+
+ _8 = Lt(const 1_usize, copy _7);
37+
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 1_usize) -> [success: bb1, unwind unreachable];
3938
}
4039

4140
bb1: {
4241
- _1 = copy (*_2)[_6];
43-
+ _1 = const 2_u32;
42+
+ _1 = copy (*_2)[1 of 2];
4443
StorageDead(_6);
4544
StorageDead(_4);
4645
StorageDead(_2);

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,16 @@
3030
StorageDead(_3);
3131
StorageLive(_6);
3232
_6 = const 1_usize;
33-
- _7 = Len((*_2));
33+
_7 = Len((*_2));
3434
- _8 = Lt(copy _6, copy _7);
3535
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, copy _6) -> [success: bb1, unwind continue];
36-
+ _7 = const 3_usize;
37-
+ _8 = const true;
38-
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 1_usize) -> [success: bb1, unwind continue];
36+
+ _8 = Lt(const 1_usize, copy _7);
37+
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 1_usize) -> [success: bb1, unwind continue];
3938
}
4039

4140
bb1: {
4241
- _1 = copy (*_2)[_6];
43-
+ _1 = const 2_u32;
42+
+ _1 = copy (*_2)[1 of 2];
4443
StorageDead(_6);
4544
StorageDead(_4);
4645
StorageDead(_2);

‎tests/mir-opt/const_prop/slice_len.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ fn main() {
88
// CHECK-LABEL: fn main(
99
// CHECK: debug a => [[a:_.*]];
1010
// CHECK: [[slice:_.*]] = copy {{.*}} as &[u32] (PointerCoercion(Unsize, AsCast));
11-
// CHECK: assert(const true,
12-
// CHECK: [[a]] = const 2_u32;
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;
1314
let a = (&[1u32, 2, 3] as &[u32])[1];
1415
}

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

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

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

2524
bb3: {

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

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

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

2524
bb3: {

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,18 @@
107107
StorageLive(_18);
108108
_18 = &(*_1);
109109
StorageLive(_19);
110-
- StorageLive(_20);
111-
+ nop;
110+
StorageLive(_20);
112111
_20 = copy (*_18);
113-
- _19 = opaque::<u32>(move _20) -> [return: bb7, unwind unreachable];
114-
+ _19 = opaque::<u32>(copy _20) -> [return: bb7, unwind unreachable];
112+
_19 = opaque::<u32>(move _20) -> [return: bb7, unwind unreachable];
115113
}
116114

117115
bb7: {
118-
- StorageDead(_20);
119-
+ nop;
116+
StorageDead(_20);
120117
StorageDead(_19);
121118
StorageLive(_21);
122119
StorageLive(_22);
123-
- _22 = copy (*_18);
124-
- _21 = opaque::<u32>(move _22) -> [return: bb8, unwind unreachable];
125-
+ _22 = copy _20;
126-
+ _21 = opaque::<u32>(copy _20) -> [return: bb8, unwind unreachable];
120+
_22 = copy (*_18);
121+
_21 = opaque::<u32>(move _22) -> [return: bb8, unwind unreachable];
127122
}
128123

129124
bb8: {
@@ -157,23 +152,18 @@
157152
StorageDead(_28);
158153
StorageDead(_27);
159154
StorageLive(_29);
160-
- StorageLive(_30);
161-
+ nop;
155+
StorageLive(_30);
162156
_30 = copy ((*_3).0: u32);
163-
- _29 = opaque::<u32>(move _30) -> [return: bb12, unwind unreachable];
164-
+ _29 = opaque::<u32>(copy _30) -> [return: bb12, unwind unreachable];
157+
_29 = opaque::<u32>(move _30) -> [return: bb12, unwind unreachable];
165158
}
166159

167160
bb12: {
168-
- StorageDead(_30);
169-
+ nop;
161+
StorageDead(_30);
170162
StorageDead(_29);
171163
StorageLive(_31);
172164
StorageLive(_32);
173-
- _32 = copy ((*_3).0: u32);
174-
- _31 = opaque::<u32>(move _32) -> [return: bb13, unwind unreachable];
175-
+ _32 = copy _30;
176-
+ _31 = opaque::<u32>(copy _30) -> [return: bb13, unwind unreachable];
165+
_32 = copy ((*_3).0: u32);
166+
_31 = opaque::<u32>(move _32) -> [return: bb13, unwind unreachable];
177167
}
178168

179169
bb13: {

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,18 @@
107107
StorageLive(_18);
108108
_18 = &(*_1);
109109
StorageLive(_19);
110-
- StorageLive(_20);
111-
+ nop;
110+
StorageLive(_20);
112111
_20 = copy (*_18);
113-
- _19 = opaque::<u32>(move _20) -> [return: bb7, unwind continue];
114-
+ _19 = opaque::<u32>(copy _20) -> [return: bb7, unwind continue];
112+
_19 = opaque::<u32>(move _20) -> [return: bb7, unwind continue];
115113
}
116114

117115
bb7: {
118-
- StorageDead(_20);
119-
+ nop;
116+
StorageDead(_20);
120117
StorageDead(_19);
121118
StorageLive(_21);
122119
StorageLive(_22);
123-
- _22 = copy (*_18);
124-
- _21 = opaque::<u32>(move _22) -> [return: bb8, unwind continue];
125-
+ _22 = copy _20;
126-
+ _21 = opaque::<u32>(copy _20) -> [return: bb8, unwind continue];
120+
_22 = copy (*_18);
121+
_21 = opaque::<u32>(move _22) -> [return: bb8, unwind continue];
127122
}
128123

129124
bb8: {
@@ -157,23 +152,18 @@
157152
StorageDead(_28);
158153
StorageDead(_27);
159154
StorageLive(_29);
160-
- StorageLive(_30);
161-
+ nop;
155+
StorageLive(_30);
162156
_30 = copy ((*_3).0: u32);
163-
- _29 = opaque::<u32>(move _30) -> [return: bb12, unwind continue];
164-
+ _29 = opaque::<u32>(copy _30) -> [return: bb12, unwind continue];
157+
_29 = opaque::<u32>(move _30) -> [return: bb12, unwind continue];
165158
}
166159

167160
bb12: {
168-
- StorageDead(_30);
169-
+ nop;
161+
StorageDead(_30);
170162
StorageDead(_29);
171163
StorageLive(_31);
172164
StorageLive(_32);
173-
- _32 = copy ((*_3).0: u32);
174-
- _31 = opaque::<u32>(move _32) -> [return: bb13, unwind continue];
175-
+ _32 = copy _30;
176-
+ _31 = opaque::<u32>(copy _30) -> [return: bb13, unwind continue];
165+
_32 = copy ((*_3).0: u32);
166+
_31 = opaque::<u32>(move _32) -> [return: bb13, unwind continue];
177167
}
178168

179169
bb13: {

‎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:614:19: 614:21};
11+
let mut _9: {closure@$DIR/gvn.rs:615:19: 615:21};
1212
let _10: ();
1313
let mut _11: fn();
14-
let mut _13: {closure@$DIR/gvn.rs:614:19: 614:21};
14+
let mut _13: {closure@$DIR/gvn.rs:615:19: 615: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:614:19: 614:21};
22+
let _7: {closure@$DIR/gvn.rs:615:19: 615: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:614:19: 614:21};
65+
- _7 = {closure@$DIR/gvn.rs:615:19: 615:21};
6666
- StorageLive(_8);
6767
+ nop;
68-
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21};
68+
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615: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:614:19: 614:21};
74-
+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21} 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));
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:614:19: 614:21};
92-
+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21} 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));
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:614:19: 614:21};
11+
let mut _9: {closure@$DIR/gvn.rs:615:19: 615:21};
1212
let _10: ();
1313
let mut _11: fn();
14-
let mut _13: {closure@$DIR/gvn.rs:614:19: 614:21};
14+
let mut _13: {closure@$DIR/gvn.rs:615:19: 615: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:614:19: 614:21};
22+
let _7: {closure@$DIR/gvn.rs:615:19: 615: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:614:19: 614:21};
65+
- _7 = {closure@$DIR/gvn.rs:615:19: 615:21};
6666
- StorageLive(_8);
6767
+ nop;
68-
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21};
68+
+ _7 = const ZeroSized: {closure@$DIR/gvn.rs:615:19: 615: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:614:19: 614:21};
74-
+ _8 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21} 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));
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:614:19: 614:21};
92-
+ _12 = const ZeroSized: {closure@$DIR/gvn.rs:614:19: 614:21} 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));
9393
StorageDead(_13);
9494
StorageLive(_14);
9595
StorageLive(_15);

‎tests/mir-opt/gvn.rs

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

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

112-
// But not through a mutable reference or a pointer.
113+
// And certainly not through a mutable reference or a pointer.
113114
// CHECK: [[mut:_.*]] = &mut _3;
114115
// CHECK: [[addmut:_.*]] = Add(
115116
// CHECK: opaque::<u64>(move [[addmut]])
@@ -137,13 +138,13 @@ fn subexpression_elimination(x: u64, y: u64, mut z: u64) {
137138
opaque(*d + x);
138139
}
139140

140-
// We can substitute again, but not with the earlier computations.
141+
// We still cannot substitute again, and never with the earlier computations.
141142
// Important: `e` is not `a`!
142143
// CHECK: [[ref2:_.*]] = &_3;
143144
// CHECK: [[deref2:_.*]] = copy (*[[ref2]]);
144-
// CHECK: [[addref2:_.*]] = Add(copy [[deref2]], copy _1);
145-
// CHECK: opaque::<u64>(copy [[addref2]])
146-
// CHECK: opaque::<u64>(copy [[addref2]])
145+
// COM: CHECK: [[addref2:_.*]] = Add(copy [[deref2]], copy _1);
146+
// COM: CHECK: opaque::<u64>(copy [[addref2]])
147+
// COM: CHECK: opaque::<u64>(copy [[addref2]])
147148
let e = &z;
148149
opaque(*e + x);
149150
opaque(*e + x);
@@ -495,15 +496,15 @@ fn dereferences(t: &mut u32, u: &impl Copy, s: &S<u32>) {
495496
unsafe { opaque(*z) };
496497
unsafe { opaque(*z) };
497498

498-
// We can reuse dereferences of `&Freeze`.
499+
// Do not reuse dereferences of `&Freeze`.
499500
// CHECK: [[ref:_.*]] = &(*_1);
500501
// CHECK: [[st7:_.*]] = copy (*[[ref]]);
501-
// CHECK: opaque::<u32>(copy [[st7]])
502-
// CHECK: opaque::<u32>(copy [[st7]])
502+
// COM: CHECK: opaque::<u32>(copy [[st7]])
503+
// COM: CHECK: opaque::<u32>(copy [[st7]])
503504
let z = &*t;
504505
opaque(*z);
505506
opaque(*z);
506-
// But not in reborrows.
507+
// Not in reborrows either.
507508
// CHECK: [[reborrow:_.*]] = &(*[[ref]]);
508509
// CHECK: opaque::<&u32>(move [[reborrow]])
509510
opaque(&*z);
@@ -516,10 +517,10 @@ fn dereferences(t: &mut u32, u: &impl Copy, s: &S<u32>) {
516517
opaque(*u);
517518
opaque(*u);
518519

519-
// `*s` is not Copy, but `(*s).0` is, so we can reuse.
520+
// `*s` is not Copy, but `(*s).0` is, but we still cannot reuse.
520521
// CHECK: [[st10:_.*]] = copy ((*_3).0: u32);
521-
// CHECK: opaque::<u32>(copy [[st10]])
522-
// CHECK: opaque::<u32>(copy [[st10]])
522+
// COM: CHECK: opaque::<u32>(copy [[st10]])
523+
// COM: CHECK: opaque::<u32>(copy [[st10]])
523524
opaque(s.0);
524525
opaque(s.0);
525526
}
@@ -736,7 +737,7 @@ fn borrowed<T: Copy + Freeze>(x: T) {
736737
// CHECK: bb1: {
737738
// CHECK-NEXT: _0 = opaque::<T>(copy _1)
738739
// CHECK: bb2: {
739-
// CHECK-NEXT: _0 = opaque::<T>(copy _1)
740+
// COM: CHECK-NEXT: _0 = opaque::<T>(copy _1)
740741
mir! {
741742
{
742743
let a = x;

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

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@
111111
StorageLive(_7);
112112
StorageLive(_8);
113113
- StorageLive(_9);
114-
- StorageLive(_10);
115-
+ nop;
116114
+ nop;
115+
StorageLive(_10);
117116
StorageLive(_11);
118117
_11 = &(*_1);
119118
_10 = core::str::<impl str>::as_ptr(move _11) -> [return: bb3, unwind unreachable];
@@ -123,9 +122,8 @@
123122
StorageDead(_11);
124123
_9 = &_10;
125124
- StorageLive(_12);
126-
- StorageLive(_13);
127-
+ nop;
128125
+ nop;
126+
StorageLive(_13);
129127
StorageLive(_14);
130128
- _14 = &(*_4);
131129
+ _14 = &(*_1);
@@ -150,12 +148,11 @@
150148
StorageLive(_17);
151149
StorageLive(_18);
152150
- _18 = copy (*_15);
153-
+ _18 = copy _10;
151+
+ _18 = copy (*_9);
154152
StorageLive(_19);
155153
- _19 = copy (*_16);
156-
- _17 = Eq(move _18, move _19);
157-
+ _19 = copy _13;
158-
+ _17 = Eq(copy _10, copy _13);
154+
+ _19 = copy (*_12);
155+
_17 = Eq(move _18, move _19);
159156
switchInt(move _17) -> [0: bb6, otherwise: bb5];
160157
}
161158

@@ -166,10 +163,8 @@
166163
StorageDead(_17);
167164
StorageDead(_16);
168165
StorageDead(_15);
169-
- StorageDead(_13);
170-
- StorageDead(_10);
171-
+ nop;
172-
+ nop;
166+
StorageDead(_13);
167+
StorageDead(_10);
173168
StorageDead(_8);
174169
StorageDead(_7);
175170
- StorageLive(_29);
@@ -218,9 +213,8 @@
218213
StorageLive(_33);
219214
StorageLive(_34);
220215
- StorageLive(_35);
221-
- StorageLive(_36);
222-
+ nop;
223216
+ nop;
217+
StorageLive(_36);
224218
StorageLive(_37);
225219
_37 = &(*_1);
226220
_36 = core::str::<impl str>::as_ptr(move _37) -> [return: bb8, unwind unreachable];
@@ -230,9 +224,8 @@
230224
StorageDead(_37);
231225
_35 = &_36;
232226
- StorageLive(_38);
233-
- StorageLive(_39);
234-
+ nop;
235227
+ nop;
228+
StorageLive(_39);
236229
StorageLive(_40);
237230
_40 = &(*_29);
238231
_39 = core::slice::<impl [u8]>::as_ptr(move _40) -> [return: bb9, unwind unreachable];
@@ -256,12 +249,11 @@
256249
StorageLive(_43);
257250
StorageLive(_44);
258251
- _44 = copy (*_41);
259-
+ _44 = copy _36;
252+
+ _44 = copy (*_35);
260253
StorageLive(_45);
261254
- _45 = copy (*_42);
262-
- _43 = Eq(move _44, move _45);
263-
+ _45 = copy _39;
264-
+ _43 = Eq(copy _36, copy _39);
255+
+ _45 = copy (*_38);
256+
_43 = Eq(move _44, move _45);
265257
switchInt(move _43) -> [0: bb11, otherwise: bb10];
266258
}
267259

@@ -272,10 +264,8 @@
272264
StorageDead(_43);
273265
StorageDead(_42);
274266
StorageDead(_41);
275-
- StorageDead(_39);
276-
- StorageDead(_36);
277-
+ nop;
278-
+ nop;
267+
StorageDead(_39);
268+
StorageDead(_36);
279269
StorageDead(_34);
280270
StorageDead(_33);
281271
_0 = const ();

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

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@
111111
StorageLive(_7);
112112
StorageLive(_8);
113113
- StorageLive(_9);
114-
- StorageLive(_10);
115-
+ nop;
116114
+ nop;
115+
StorageLive(_10);
117116
StorageLive(_11);
118117
_11 = &(*_1);
119118
_10 = core::str::<impl str>::as_ptr(move _11) -> [return: bb3, unwind continue];
@@ -123,9 +122,8 @@
123122
StorageDead(_11);
124123
_9 = &_10;
125124
- StorageLive(_12);
126-
- StorageLive(_13);
127-
+ nop;
128125
+ nop;
126+
StorageLive(_13);
129127
StorageLive(_14);
130128
- _14 = &(*_4);
131129
+ _14 = &(*_1);
@@ -150,12 +148,11 @@
150148
StorageLive(_17);
151149
StorageLive(_18);
152150
- _18 = copy (*_15);
153-
+ _18 = copy _10;
151+
+ _18 = copy (*_9);
154152
StorageLive(_19);
155153
- _19 = copy (*_16);
156-
- _17 = Eq(move _18, move _19);
157-
+ _19 = copy _13;
158-
+ _17 = Eq(copy _10, copy _13);
154+
+ _19 = copy (*_12);
155+
_17 = Eq(move _18, move _19);
159156
switchInt(move _17) -> [0: bb6, otherwise: bb5];
160157
}
161158

@@ -166,10 +163,8 @@
166163
StorageDead(_17);
167164
StorageDead(_16);
168165
StorageDead(_15);
169-
- StorageDead(_13);
170-
- StorageDead(_10);
171-
+ nop;
172-
+ nop;
166+
StorageDead(_13);
167+
StorageDead(_10);
173168
StorageDead(_8);
174169
StorageDead(_7);
175170
- StorageLive(_29);
@@ -218,9 +213,8 @@
218213
StorageLive(_33);
219214
StorageLive(_34);
220215
- StorageLive(_35);
221-
- StorageLive(_36);
222-
+ nop;
223216
+ nop;
217+
StorageLive(_36);
224218
StorageLive(_37);
225219
_37 = &(*_1);
226220
_36 = core::str::<impl str>::as_ptr(move _37) -> [return: bb8, unwind continue];
@@ -230,9 +224,8 @@
230224
StorageDead(_37);
231225
_35 = &_36;
232226
- StorageLive(_38);
233-
- StorageLive(_39);
234-
+ nop;
235227
+ nop;
228+
StorageLive(_39);
236229
StorageLive(_40);
237230
_40 = &(*_29);
238231
_39 = core::slice::<impl [u8]>::as_ptr(move _40) -> [return: bb9, unwind continue];
@@ -256,12 +249,11 @@
256249
StorageLive(_43);
257250
StorageLive(_44);
258251
- _44 = copy (*_41);
259-
+ _44 = copy _36;
252+
+ _44 = copy (*_35);
260253
StorageLive(_45);
261254
- _45 = copy (*_42);
262-
- _43 = Eq(move _44, move _45);
263-
+ _45 = copy _39;
264-
+ _43 = Eq(copy _36, copy _39);
255+
+ _45 = copy (*_38);
256+
_43 = Eq(move _44, move _45);
265257
switchInt(move _43) -> [0: bb11, otherwise: bb10];
266258
}
267259

@@ -272,10 +264,8 @@
272264
StorageDead(_43);
273265
StorageDead(_42);
274266
StorageDead(_41);
275-
- StorageDead(_39);
276-
- StorageDead(_36);
277-
+ nop;
278-
+ nop;
267+
StorageDead(_39);
268+
StorageDead(_36);
279269
StorageDead(_34);
280270
StorageDead(_33);
281271
_0 = const ();

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

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -758,39 +758,32 @@
758758
StorageLive(_126);
759759
_126 = &_3;
760760
StorageLive(_127);
761-
- StorageLive(_128);
762-
- StorageLive(_129);
763-
+ nop;
764-
+ nop;
761+
StorageLive(_128);
762+
StorageLive(_129);
765763
_129 = copy (*_126);
766764
StorageLive(_130);
767765
_130 = copy _1;
768766
- _128 = Add(move _129, move _130);
769-
+ _128 = Add(copy _129, copy _1);
767+
+ _128 = Add(move _129, copy _1);
770768
StorageDead(_130);
771-
- StorageDead(_129);
772-
- _127 = opaque::<u64>(move _128) -> [return: bb35, unwind unreachable];
773-
+ nop;
774-
+ _127 = opaque::<u64>(copy _128) -> [return: bb35, unwind unreachable];
769+
StorageDead(_129);
770+
_127 = opaque::<u64>(move _128) -> [return: bb35, unwind unreachable];
775771
}
776772

777773
bb35: {
778-
- StorageDead(_128);
779-
+ nop;
774+
StorageDead(_128);
780775
StorageDead(_127);
781776
StorageLive(_131);
782777
StorageLive(_132);
783778
StorageLive(_133);
784-
- _133 = copy (*_126);
785-
+ _133 = copy _129;
779+
_133 = copy (*_126);
786780
StorageLive(_134);
787781
_134 = copy _1;
788782
- _132 = Add(move _133, move _134);
789-
+ _132 = copy _128;
783+
+ _132 = Add(move _133, copy _1);
790784
StorageDead(_134);
791785
StorageDead(_133);
792-
- _131 = opaque::<u64>(move _132) -> [return: bb36, unwind unreachable];
793-
+ _131 = opaque::<u64>(copy _128) -> [return: bb36, unwind unreachable];
786+
_131 = opaque::<u64>(move _132) -> [return: bb36, unwind unreachable];
794787
}
795788

796789
bb36: {
@@ -906,39 +899,32 @@
906899
StorageLive(_163);
907900
_163 = &_3;
908901
StorageLive(_164);
909-
- StorageLive(_165);
910-
- StorageLive(_166);
911-
+ nop;
912-
+ nop;
902+
StorageLive(_165);
903+
StorageLive(_166);
913904
_166 = copy (*_163);
914905
StorageLive(_167);
915906
_167 = copy _1;
916907
- _165 = Add(move _166, move _167);
917-
+ _165 = Add(copy _166, copy _1);
908+
+ _165 = Add(move _166, copy _1);
918909
StorageDead(_167);
919-
- StorageDead(_166);
920-
- _164 = opaque::<u64>(move _165) -> [return: bb43, unwind unreachable];
921-
+ nop;
922-
+ _164 = opaque::<u64>(copy _165) -> [return: bb43, unwind unreachable];
910+
StorageDead(_166);
911+
_164 = opaque::<u64>(move _165) -> [return: bb43, unwind unreachable];
923912
}
924913

925914
bb43: {
926-
- StorageDead(_165);
927-
+ nop;
915+
StorageDead(_165);
928916
StorageDead(_164);
929917
StorageLive(_168);
930918
StorageLive(_169);
931919
StorageLive(_170);
932-
- _170 = copy (*_163);
933-
+ _170 = copy _166;
920+
_170 = copy (*_163);
934921
StorageLive(_171);
935922
_171 = copy _1;
936923
- _169 = Add(move _170, move _171);
937-
+ _169 = copy _165;
924+
+ _169 = Add(move _170, copy _1);
938925
StorageDead(_171);
939926
StorageDead(_170);
940-
- _168 = opaque::<u64>(move _169) -> [return: bb44, unwind unreachable];
941-
+ _168 = opaque::<u64>(copy _165) -> [return: bb44, unwind unreachable];
927+
_168 = opaque::<u64>(move _169) -> [return: bb44, unwind unreachable];
942928
}
943929

944930
bb44: {

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

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -758,39 +758,32 @@
758758
StorageLive(_126);
759759
_126 = &_3;
760760
StorageLive(_127);
761-
- StorageLive(_128);
762-
- StorageLive(_129);
763-
+ nop;
764-
+ nop;
761+
StorageLive(_128);
762+
StorageLive(_129);
765763
_129 = copy (*_126);
766764
StorageLive(_130);
767765
_130 = copy _1;
768766
- _128 = Add(move _129, move _130);
769-
+ _128 = Add(copy _129, copy _1);
767+
+ _128 = Add(move _129, copy _1);
770768
StorageDead(_130);
771-
- StorageDead(_129);
772-
- _127 = opaque::<u64>(move _128) -> [return: bb35, unwind continue];
773-
+ nop;
774-
+ _127 = opaque::<u64>(copy _128) -> [return: bb35, unwind continue];
769+
StorageDead(_129);
770+
_127 = opaque::<u64>(move _128) -> [return: bb35, unwind continue];
775771
}
776772

777773
bb35: {
778-
- StorageDead(_128);
779-
+ nop;
774+
StorageDead(_128);
780775
StorageDead(_127);
781776
StorageLive(_131);
782777
StorageLive(_132);
783778
StorageLive(_133);
784-
- _133 = copy (*_126);
785-
+ _133 = copy _129;
779+
_133 = copy (*_126);
786780
StorageLive(_134);
787781
_134 = copy _1;
788782
- _132 = Add(move _133, move _134);
789-
+ _132 = copy _128;
783+
+ _132 = Add(move _133, copy _1);
790784
StorageDead(_134);
791785
StorageDead(_133);
792-
- _131 = opaque::<u64>(move _132) -> [return: bb36, unwind continue];
793-
+ _131 = opaque::<u64>(copy _128) -> [return: bb36, unwind continue];
786+
_131 = opaque::<u64>(move _132) -> [return: bb36, unwind continue];
794787
}
795788

796789
bb36: {
@@ -906,39 +899,32 @@
906899
StorageLive(_163);
907900
_163 = &_3;
908901
StorageLive(_164);
909-
- StorageLive(_165);
910-
- StorageLive(_166);
911-
+ nop;
912-
+ nop;
902+
StorageLive(_165);
903+
StorageLive(_166);
913904
_166 = copy (*_163);
914905
StorageLive(_167);
915906
_167 = copy _1;
916907
- _165 = Add(move _166, move _167);
917-
+ _165 = Add(copy _166, copy _1);
908+
+ _165 = Add(move _166, copy _1);
918909
StorageDead(_167);
919-
- StorageDead(_166);
920-
- _164 = opaque::<u64>(move _165) -> [return: bb43, unwind continue];
921-
+ nop;
922-
+ _164 = opaque::<u64>(copy _165) -> [return: bb43, unwind continue];
910+
StorageDead(_166);
911+
_164 = opaque::<u64>(move _165) -> [return: bb43, unwind continue];
923912
}
924913

925914
bb43: {
926-
- StorageDead(_165);
927-
+ nop;
915+
StorageDead(_165);
928916
StorageDead(_164);
929917
StorageLive(_168);
930918
StorageLive(_169);
931919
StorageLive(_170);
932-
- _170 = copy (*_163);
933-
+ _170 = copy _166;
920+
_170 = copy (*_163);
934921
StorageLive(_171);
935922
_171 = copy _1;
936923
- _169 = Add(move _170, move _171);
937-
+ _169 = copy _165;
924+
+ _169 = Add(move _170, copy _1);
938925
StorageDead(_171);
939926
StorageDead(_170);
940-
- _168 = opaque::<u64>(move _169) -> [return: bb44, unwind continue];
941-
+ _168 = opaque::<u64>(copy _165) -> [return: bb44, unwind continue];
927+
_168 = opaque::<u64>(move _169) -> [return: bb44, unwind continue];
942928
}
943929

944930
bb44: {

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717
StorageLive(_3);
1818
_5 = const f::promoted[0];
1919
_3 = &(*_5);
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;
20+
_2 = copy ((*_3).1: E);
21+
- StorageLive(_1);
22+
+ nop;
23+
_1 = copy ((_2 as A).1: u32);
2524
StorageDead(_3);
2625
StorageDead(_2);
27-
- _0 = copy _1;
28-
+ _0 = const 0_u32;
29-
StorageDead(_1);
26+
_0 = copy _1;
27+
- StorageDead(_1);
28+
+ nop;
3029
return;
3130
}
3231
}

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717
StorageLive(_3);
1818
_5 = const f::promoted[0];
1919
_3 = &(*_5);
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;
20+
_2 = copy ((*_3).1: E);
21+
- StorageLive(_1);
22+
+ nop;
23+
_1 = copy ((_2 as A).1: u32);
2524
StorageDead(_3);
2625
StorageDead(_2);
27-
- _0 = copy _1;
28-
+ _0 = const 0_u32;
29-
StorageDead(_1);
26+
_0 = copy _1;
27+
- StorageDead(_1);
28+
+ nop;
3029
return;
3130
}
3231
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//! Regression test for <https://github.com/rust-lang/rust/issues/130853>
2+
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
3+
4+
fn src(x: &&u8) -> bool {
5+
// CHECK-LABEL: fn src(
6+
// CHECK-NOT: _0 = const true;
7+
// CHECK: _0 = Eq({{.*}}, {{.*}});
8+
// CHECK-NOT: _0 = const true;
9+
let y = **x;
10+
unsafe { unknown() };
11+
**x == y
12+
}
13+
14+
#[inline(never)]
15+
unsafe fn unknown() {
16+
// CHECK-LABEL: fn unknown(
17+
}
18+
19+
fn main() {
20+
// CHECK-LABEL: fn main(
21+
src(&&0);
22+
}
23+
24+
// EMIT_MIR deref_nested_borrows.src.GVN.diff
25+
// EMIT_MIR deref_nested_borrows.src.PreCodegen.after.mir
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
- // MIR for `src` before GVN
2+
+ // MIR for `src` after GVN
3+
4+
fn src(_1: &&u8) -> bool {
5+
debug x => _1;
6+
let mut _0: bool;
7+
let _2: u8;
8+
let _3: ();
9+
let mut _4: u8;
10+
let mut _5: u8;
11+
let mut _6: &u8;
12+
let mut _7: &u8;
13+
scope 1 {
14+
debug y => _2;
15+
}
16+
17+
bb0: {
18+
- StorageLive(_2);
19+
- _6 = deref_copy (*_1);
20+
+ nop;
21+
+ _6 = copy (*_1);
22+
_2 = copy (*_6);
23+
_3 = unknown() -> [return: bb1, unwind unreachable];
24+
}
25+
26+
bb1: {
27+
StorageLive(_4);
28+
- _7 = deref_copy (*_1);
29+
+ _7 = copy (*_1);
30+
_4 = copy (*_7);
31+
StorageLive(_5);
32+
_5 = copy _2;
33+
- _0 = Eq(move _4, move _5);
34+
+ _0 = Eq(move _4, copy _2);
35+
StorageDead(_5);
36+
StorageDead(_4);
37+
- StorageDead(_2);
38+
+ nop;
39+
return;
40+
}
41+
}
42+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
- // MIR for `src` before GVN
2+
+ // MIR for `src` after GVN
3+
4+
fn src(_1: &&u8) -> bool {
5+
debug x => _1;
6+
let mut _0: bool;
7+
let _2: u8;
8+
let _3: ();
9+
let mut _4: u8;
10+
let mut _5: u8;
11+
let mut _6: &u8;
12+
let mut _7: &u8;
13+
scope 1 {
14+
debug y => _2;
15+
}
16+
17+
bb0: {
18+
- StorageLive(_2);
19+
- _6 = deref_copy (*_1);
20+
+ nop;
21+
+ _6 = copy (*_1);
22+
_2 = copy (*_6);
23+
_3 = unknown() -> [return: bb1, unwind continue];
24+
}
25+
26+
bb1: {
27+
StorageLive(_4);
28+
- _7 = deref_copy (*_1);
29+
+ _7 = copy (*_1);
30+
_4 = copy (*_7);
31+
StorageLive(_5);
32+
_5 = copy _2;
33+
- _0 = Eq(move _4, move _5);
34+
+ _0 = Eq(move _4, copy _2);
35+
StorageDead(_5);
36+
StorageDead(_4);
37+
- StorageDead(_2);
38+
+ nop;
39+
return;
40+
}
41+
}
42+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// MIR for `src` after PreCodegen
2+
3+
fn src(_1: &&u8) -> bool {
4+
debug x => _1;
5+
let mut _0: bool;
6+
let mut _2: &u8;
7+
let _3: u8;
8+
let _4: ();
9+
let mut _5: &u8;
10+
let mut _6: u8;
11+
scope 1 {
12+
debug y => _3;
13+
}
14+
15+
bb0: {
16+
_2 = copy (*_1);
17+
_3 = copy (*_2);
18+
_4 = unknown() -> [return: bb1, unwind unreachable];
19+
}
20+
21+
bb1: {
22+
StorageLive(_6);
23+
_5 = copy (*_1);
24+
_6 = copy (*_5);
25+
_0 = Eq(move _6, copy _3);
26+
StorageDead(_6);
27+
return;
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// MIR for `src` after PreCodegen
2+
3+
fn src(_1: &&u8) -> bool {
4+
debug x => _1;
5+
let mut _0: bool;
6+
let mut _2: &u8;
7+
let _3: u8;
8+
let _4: ();
9+
let mut _5: &u8;
10+
let mut _6: u8;
11+
scope 1 {
12+
debug y => _3;
13+
}
14+
15+
bb0: {
16+
_2 = copy (*_1);
17+
_3 = copy (*_2);
18+
_4 = unknown() -> [return: bb1, unwind continue];
19+
}
20+
21+
bb1: {
22+
StorageLive(_6);
23+
_5 = copy (*_1);
24+
_6 = copy (*_5);
25+
_0 = Eq(move _6, copy _3);
26+
StorageDead(_6);
27+
return;
28+
}
29+
}

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

Lines changed: 128 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -4,182 +4,200 @@ 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 _5: &usize;
7+
let mut _5: &(usize, usize, usize, usize);
88
let _6: &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;
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;
2528
scope 1 {
2629
debug a => _4;
27-
debug b => _5;
28-
debug c => _6;
29-
debug d => _7;
30+
debug b => _6;
31+
debug c => _8;
32+
debug d => _10;
3033
scope 2 (inlined std::cmp::impls::<impl PartialOrd for &usize>::le) {
31-
debug self => _8;
32-
debug other => _10;
34+
debug self => _11;
35+
debug other => _13;
3336
scope 3 (inlined std::cmp::impls::<impl PartialOrd for usize>::le) {
3437
debug self => _4;
35-
debug other => _6;
36-
let mut _11: usize;
37-
let mut _12: usize;
38+
debug other => _8;
39+
let mut _14: usize;
40+
let mut _15: usize;
3841
}
3942
}
4043
scope 4 (inlined std::cmp::impls::<impl PartialOrd for &usize>::le) {
41-
debug self => _14;
42-
debug other => _16;
44+
debug self => _17;
45+
debug other => _19;
4346
scope 5 (inlined std::cmp::impls::<impl PartialOrd for usize>::le) {
44-
debug self => _7;
45-
debug other => _5;
46-
let mut _17: usize;
47-
let mut _18: usize;
47+
debug self => _10;
48+
debug other => _6;
49+
let mut _20: usize;
50+
let mut _21: usize;
4851
}
4952
}
5053
scope 6 (inlined std::cmp::impls::<impl PartialOrd for &usize>::le) {
51-
debug self => _20;
52-
debug other => _22;
54+
debug self => _23;
55+
debug other => _25;
5356
scope 7 (inlined std::cmp::impls::<impl PartialOrd for usize>::le) {
54-
debug self => _6;
57+
debug self => _8;
5558
debug other => _4;
59+
let mut _26: usize;
60+
let mut _27: usize;
5661
}
5762
}
5863
scope 8 (inlined std::cmp::impls::<impl PartialOrd for &usize>::le) {
59-
debug self => _24;
60-
debug other => _26;
64+
debug self => _29;
65+
debug other => _31;
6166
scope 9 (inlined std::cmp::impls::<impl PartialOrd for usize>::le) {
62-
debug self => _5;
63-
debug other => _7;
64-
let mut _27: usize;
65-
let mut _28: usize;
67+
debug self => _6;
68+
debug other => _10;
69+
let mut _32: usize;
70+
let mut _33: usize;
6671
}
6772
}
6873
}
6974

7075
bb0: {
7176
_3 = copy (*_2);
7277
_4 = &((*_3).0: usize);
73-
_5 = &((*_3).1: usize);
74-
_6 = &((*_3).2: usize);
75-
_7 = &((*_3).3: 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;
7687
StorageLive(_13);
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];
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];
8799
}
88100

89101
bb1: {
90-
StorageDead(_9);
91-
StorageDead(_10);
92-
StorageDead(_8);
102+
StorageDead(_12);
103+
StorageDead(_13);
104+
StorageDead(_11);
93105
goto -> bb4;
94106
}
95107

96108
bb2: {
97-
StorageDead(_9);
98-
StorageDead(_10);
99-
StorageDead(_8);
100-
StorageLive(_19);
101-
StorageLive(_14);
102-
_14 = &_7;
103-
StorageLive(_16);
104-
StorageLive(_15);
105-
_15 = copy _5;
106-
_16 = &_15;
109+
StorageDead(_12);
110+
StorageDead(_13);
111+
StorageDead(_11);
112+
StorageLive(_22);
107113
StorageLive(_17);
108-
_17 = copy ((*_3).3: usize);
114+
_17 = &_10;
115+
StorageLive(_19);
109116
StorageLive(_18);
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];
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];
115127
}
116128

117129
bb3: {
118-
StorageDead(_15);
119-
StorageDead(_16);
120-
StorageDead(_14);
130+
StorageDead(_18);
131+
StorageDead(_19);
132+
StorageDead(_17);
121133
goto -> bb4;
122134
}
123135

124136
bb4: {
137+
StorageLive(_28);
125138
StorageLive(_23);
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];
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];
134152
}
135153

136154
bb5: {
137-
StorageDead(_21);
138-
StorageDead(_22);
139-
StorageDead(_20);
155+
StorageDead(_24);
156+
StorageDead(_25);
157+
StorageDead(_23);
140158
_0 = const false;
141159
goto -> bb7;
142160
}
143161

144162
bb6: {
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);
161-
StorageDead(_25);
162-
StorageDead(_26);
163163
StorageDead(_24);
164+
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);
164182
goto -> bb7;
165183
}
166184

167185
bb7: {
168-
StorageDead(_23);
186+
StorageDead(_28);
169187
goto -> bb9;
170188
}
171189

172190
bb8: {
173-
StorageDead(_15);
174-
StorageDead(_16);
175-
StorageDead(_14);
191+
StorageDead(_18);
192+
StorageDead(_19);
193+
StorageDead(_17);
176194
_0 = const true;
177195
goto -> bb9;
178196
}
179197

180198
bb9: {
181-
StorageDead(_19);
182-
StorageDead(_13);
199+
StorageDead(_22);
200+
StorageDead(_16);
183201
return;
184202
}
185203
}

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

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,46 @@ 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 _5: usize;
7+
let mut _5: &(usize, usize, usize, usize);
88
let _6: usize;
9-
let _7: usize;
10-
let mut _8: bool;
11-
let mut _9: bool;
12-
let mut _10: bool;
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;
1316
scope 1 {
1417
debug a => _4;
15-
debug b => _5;
16-
debug c => _6;
17-
debug d => _7;
18+
debug b => _6;
19+
debug c => _8;
20+
debug d => _10;
1821
}
1922

2023
bb0: {
2124
_3 = copy (*_2);
2225
_4 = copy ((*_3).0: usize);
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];
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];
2935
}
3036

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

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

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

4854
bb4: {
49-
_0 = Le(copy _5, copy _7);
55+
_0 = Le(copy _6, copy _10);
5056
goto -> bb5;
5157
}
5258

5359
bb5: {
54-
StorageDead(_10);
60+
StorageDead(_13);
5561
goto -> bb7;
5662
}
5763

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

6369
bb7: {
64-
StorageDead(_9);
65-
StorageDead(_8);
70+
StorageDead(_12);
71+
StorageDead(_11);
6672
return;
6773
}
6874
}

0 commit comments

Comments
 (0)
Please sign in to comment.