Skip to content

Commit cf48e8a

Browse files
committed
Auto merge of #116270 - cjgillot:gvn-aggregate, r=oli-obk,RalfJung
See through aggregates in GVN This PR is extracted from rust-lang/rust#111344 The first 2 commit are cleanups to avoid repeated work. I propose to stop removing useless assignments as part of this pass, and let a later `SimplifyLocals` do it. This makes tests easier to read (among others). The next 3 commits add a constant folding mechanism to the GVN pass, presented in rust-lang/rust#116012. ~This pass is designed to only use global allocations, to avoid any risk of accidental modification of the stored state.~ The following commits implement opportunistic simplifications, in particular: - projections of aggregates: `MyStruct { x: a }.x` gets replaced by `a`, works with enums too; - projections of arrays: `[a, b][0]` becomes `a`; - projections of repeat expressions: `[a; N][x]` becomes `a`; - transform arrays of equal operands into a repeat rvalue. Fixes #3090 r? `@oli-obk`
2 parents 87d1311 + 10b9c47 commit cf48e8a

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

tests/pass/function_pointers.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ fn main() {
8080
// but Miri currently uses a fixed address for monomorphic functions.
8181
assert!(return_fn_ptr(i) == i);
8282
assert!(return_fn_ptr(i) as unsafe fn() -> i32 == i as fn() -> i32 as unsafe fn() -> i32);
83-
// We don't check anything for `f`. Miri gives it many different addresses
84-
// but mir-opts can turn them into the same address.
85-
let _val = return_fn_ptr(f) != f;
83+
// Miri gives different addresses to different reifications of a generic function.
84+
assert!(return_fn_ptr(f) != f);
8685
// However, if we only turn `f` into a function pointer and use that pointer,
8786
// it is equal to itself.
8887
let f2 = f as fn() -> i32;

0 commit comments

Comments
 (0)