add test for const type_id misoptimization

This commit is contained in:
Lukas Markeffsky
2025-02-11 01:10:05 +01:00
parent 4bb6ec05b0
commit 4898753d5d
2 changed files with 35 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
- // MIR for `cursed_is_i32` before GVN
+ // MIR for `cursed_is_i32` after GVN
fn cursed_is_i32() -> bool {
let mut _0: bool;
bb0: {
- _0 = Eq(const cursed_is_i32::<T>::{constant#0}, const cursed_is_i32::<T>::{constant#1});
+ _0 = const false;
return;
}
}

View File

@@ -0,0 +1,22 @@
//@ test-mir-pass: GVN
//@ compile-flags: -C opt-level=2
#![feature(core_intrinsics)]
fn generic<T>() {}
const fn type_id_of_val<T: 'static>(_: &T) -> u128 {
std::intrinsics::type_id::<T>()
}
// EMIT_MIR gvn_type_id_polymorphic.cursed_is_i32.GVN.diff
fn cursed_is_i32<T: 'static>() -> bool {
// CHECK-LABEL: fn cursed_is_i32(
// CHECK: _0 = const false;
// CHECK-NEXT: return;
(const { type_id_of_val(&generic::<T>) } == const { type_id_of_val(&generic::<i32>) })
}
fn main() {
dbg!(cursed_is_i32::<i32>());
}