Skip to content

Commit f694211

Browse files
committed
Add a GVN test for 127089 that doesn't optimize to a constant
1 parent c9f36f8 commit f694211

3 files changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
- // MIR for `remove_casts_must_change_both_sides` before GVN
2+
+ // MIR for `remove_casts_must_change_both_sides` after GVN
3+
4+
fn remove_casts_must_change_both_sides(_1: &*mut u8, _2: *mut u8) -> bool {
5+
let mut _0: bool;
6+
let mut _3: *const u8;
7+
let mut _4: *const u8;
8+
9+
bb0: {
10+
_3 = (*_1) as *const u8 (PtrToPtr);
11+
_4 = _2 as *const u8 (PtrToPtr);
12+
_0 = Eq(_3, _4);
13+
return;
14+
}
15+
}
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
- // MIR for `remove_casts_must_change_both_sides` before GVN
2+
+ // MIR for `remove_casts_must_change_both_sides` after GVN
3+
4+
fn remove_casts_must_change_both_sides(_1: &*mut u8, _2: *mut u8) -> bool {
5+
let mut _0: bool;
6+
let mut _3: *const u8;
7+
let mut _4: *const u8;
8+
9+
bb0: {
10+
_3 = (*_1) as *const u8 (PtrToPtr);
11+
_4 = _2 as *const u8 (PtrToPtr);
12+
_0 = Eq(_3, _4);
13+
return;
14+
}
15+
}
16+

tests/mir-opt/gvn.rs

+20
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,25 @@ unsafe fn cast_pointer_then_transmute(thin: *mut u32, fat: *mut [u8]) {
926926
let fat_addr: usize = std::intrinsics::transmute(fat as *const ());
927927
}
928928

929+
#[custom_mir(dialect = "analysis")]
930+
fn remove_casts_must_change_both_sides(mut_a: &*mut u8, mut_b: *mut u8) -> bool {
931+
// CHECK-LABEL: fn remove_casts_must_change_both_sides(
932+
mir! {
933+
// We'd like to remove these casts, but we can't change *both* of them
934+
// to be locals, so make sure we don't change one without the other, as
935+
// that would be a type error.
936+
{
937+
// CHECK: [[A:_.+]] = (*_1) as *const u8 (PtrToPtr);
938+
let a = *mut_a as *const u8;
939+
// CHECK: [[B:_.+]] = _2 as *const u8 (PtrToPtr);
940+
let b = mut_b as *const u8;
941+
// CHECK: _0 = Eq([[A]], [[B]]);
942+
RET = a == b;
943+
Return()
944+
}
945+
}
946+
}
947+
929948
fn main() {
930949
subexpression_elimination(2, 4, 5);
931950
wrap_unwrap(5);
@@ -995,3 +1014,4 @@ fn identity<T>(x: T) -> T {
9951014
// EMIT_MIR gvn.generic_cast_metadata.GVN.diff
9961015
// EMIT_MIR gvn.cast_pointer_eq.GVN.diff
9971016
// EMIT_MIR gvn.cast_pointer_then_transmute.GVN.diff
1017+
// EMIT_MIR gvn.remove_casts_must_change_both_sides.GVN.diff

0 commit comments

Comments
 (0)