Skip to content

Commit 0debe2b

Browse files
committed
Auto merge of #143271 - cjgillot:gvn-types, r=<try>
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. r? `@ghost` for perf
2 parents 6988a8f + 2684875 commit 0debe2b

8 files changed

+226
-282
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 217 additions & 272 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

0 commit comments

Comments
 (0)