Skip to content

Commit d283ea0

Browse files
authored
Rollup merge of rust-lang#143271 - cjgillot:gvn-types, r=oli-obk
Store the type of each GVN value MIR is fully typed, so type information is an integral part of what defines a value. GVN currently tries to circumvent storing types, which creates all sorts of complexities. This PR stores the type along with the enum `Value` when defining a value index. This allows to simplify a lot of code. Fixes rust-lang#128094 Fixes rust-lang#135128 r? ``@ghost`` for perf
2 parents 0c86a60 + 4a95b16 commit d283ea0

12 files changed

+309
-310
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 255 additions & 298 deletions
Large diffs are not rendered by default.

tests/mir-opt/const_prop/transmute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub unsafe fn undef_union_as_integer() -> u32 {
5656
pub unsafe fn unreachable_direct() -> ! {
5757
// CHECK-LABEL: fn unreachable_direct(
5858
// CHECK: = const ();
59-
// CHECK: = const () as Never (Transmute);
59+
// CHECK: = const ZeroSized: Never;
6060
let x: Never = unsafe { transmute(()) };
6161
match x {}
6262
}

tests/mir-opt/const_prop/transmute.unreachable_direct.GVN.32bit.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- _2 = ();
1616
- _1 = move _2 as Never (Transmute);
1717
+ _2 = const ();
18-
+ _1 = const () as Never (Transmute);
18+
+ _1 = const ZeroSized: Never;
1919
unreachable;
2020
}
2121
}

tests/mir-opt/const_prop/transmute.unreachable_direct.GVN.64bit.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- _2 = ();
1616
- _1 = move _2 as Never (Transmute);
1717
+ _2 = const ();
18-
+ _1 = const () as Never (Transmute);
18+
+ _1 = const ZeroSized: Never;
1919
unreachable;
2020
}
2121
}

tests/mir-opt/gvn.generic_cast_metadata.GVN.panic-abort.diff

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

1919
bb0: {
2020
_4 = copy _1 as *const T (PtrToPtr);
21-
_5 = PtrMetadata(copy _4);
21+
- _5 = PtrMetadata(copy _4);
22+
+ _5 = const ();
2223
_6 = copy _1 as *const (&A, [T]) (PtrToPtr);
2324
- _7 = PtrMetadata(copy _6);
2425
+ _7 = PtrMetadata(copy _1);

tests/mir-opt/gvn.generic_cast_metadata.GVN.panic-unwind.diff

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

1919
bb0: {
2020
_4 = copy _1 as *const T (PtrToPtr);
21-
_5 = PtrMetadata(copy _4);
21+
- _5 = PtrMetadata(copy _4);
22+
+ _5 = const ();
2223
_6 = copy _1 as *const (&A, [T]) (PtrToPtr);
2324
- _7 = PtrMetadata(copy _6);
2425
+ _7 = PtrMetadata(copy _1);

tests/mir-opt/gvn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ fn generic_cast_metadata<T, A: ?Sized, B: ?Sized>(ps: *const [T], pa: *const A,
869869

870870
// Metadata usize -> (), do not optimize.
871871
// CHECK: [[T:_.+]] = copy _1 as
872-
// CHECK-NEXT: PtrMetadata(copy [[T]])
872+
// CHECK-NEXT: const ();
873873
let t1 = CastPtrToPtr::<_, *const T>(ps);
874874
let m1 = PtrMetadata(t1);
875875

tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
109109
}
110110

111111
bb4: {
112-
StorageLive(_15);
113112
_14 = &mut _13;
114113
_15 = <Enumerate<std::slice::Iter<'_, T>> as Iterator>::next(move _14) -> [return: bb5, unwind: bb11];
115114
}
@@ -120,7 +119,6 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
120119
}
121120

122121
bb6: {
123-
StorageDead(_15);
124122
StorageDead(_13);
125123
drop(_2) -> [return: bb7, unwind continue];
126124
}
@@ -135,14 +133,13 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
135133
StorageLive(_19);
136134
_19 = &_2;
137135
StorageLive(_20);
138-
_20 = (copy _17, copy _18);
136+
_20 = copy ((_15 as Some).0: (usize, &T));
139137
_21 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _19, move _20) -> [return: bb9, unwind: bb11];
140138
}
141139

142140
bb9: {
143141
StorageDead(_20);
144142
StorageDead(_19);
145-
StorageDead(_15);
146143
goto -> bb4;
147144
}
148145

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
//@ known-bug: rust-lang/rust#128094
1+
//! Verify that we do not ICE when a coroutine body is malformed.
22
//@ compile-flags: -Zmir-enable-passes=+GVN
33
//@ edition: 2018
44

55
pub enum Request {
66
TestSome(T),
7+
//~^ ERROR cannot find type `T` in this scope [E0412]
78
}
89

910
pub async fn handle_event(event: Request) {
1011
async move {
1112
static instance: Request = Request { bar: 17 };
13+
//~^ ERROR expected struct, variant or union type, found enum `Request` [E0574]
1214
&instance
1315
}
1416
.await;
1517
}
18+
19+
fn main() {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0412]: cannot find type `T` in this scope
2+
--> $DIR/gvn-nonsensical-coroutine-layout.rs:6:14
3+
|
4+
LL | TestSome(T),
5+
| ^ not found in this scope
6+
|
7+
help: you might be missing a type parameter
8+
|
9+
LL | pub enum Request<T> {
10+
| +++
11+
12+
error[E0574]: expected struct, variant or union type, found enum `Request`
13+
--> $DIR/gvn-nonsensical-coroutine-layout.rs:12:36
14+
|
15+
LL | static instance: Request = Request { bar: 17 };
16+
| ^^^^^^^ not a struct, variant or union type
17+
|
18+
help: consider importing this struct instead
19+
|
20+
LL + use std::error::Request;
21+
|
22+
23+
error: aborting due to 2 previous errors
24+
25+
Some errors have detailed explanations: E0412, E0574.
26+
For more information about an error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)