2022-12-08 18:33:14 -06:00
|
|
|
// compile-flags: -O -Z merge-functions=disabled
|
2021-12-08 21:40:23 -06:00
|
|
|
|
2021-12-05 14:55:50 -06:00
|
|
|
#![crate_type = "lib"]
|
2022-12-08 00:30:07 -06:00
|
|
|
#![feature(core_intrinsics)]
|
2021-12-05 14:55:50 -06:00
|
|
|
|
|
|
|
// This test checks that we annotate alignment loads from vtables with nonzero range metadata,
|
|
|
|
// and that this allows LLVM to eliminate redundant `align >= 1` checks.
|
|
|
|
|
|
|
|
pub trait Trait {
|
|
|
|
fn f(&self);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct WrapperWithAlign1<T: ?Sized> { x: u8, y: T }
|
|
|
|
|
|
|
|
pub struct WrapperWithAlign2<T: ?Sized> { x: u16, y: T }
|
|
|
|
|
|
|
|
pub struct Struct<W: ?Sized> {
|
|
|
|
_field: i8,
|
|
|
|
dst: W,
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @eliminates_runtime_check_when_align_1
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn eliminates_runtime_check_when_align_1(
|
|
|
|
x: &Struct<WrapperWithAlign1<dyn Trait>>
|
|
|
|
) -> &WrapperWithAlign1<dyn Trait> {
|
|
|
|
// CHECK: load [[USIZE:i[0-9]+]], {{.+}} !range [[RANGE_META:![0-9]+]]
|
2022-03-01 15:07:46 -06:00
|
|
|
// CHECK-NOT: llvm.umax
|
2021-12-05 14:55:50 -06:00
|
|
|
// CHECK-NOT: icmp
|
|
|
|
// CHECK-NOT: select
|
|
|
|
// CHECK: ret
|
|
|
|
&x.dst
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @does_not_eliminate_runtime_check_when_align_2
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn does_not_eliminate_runtime_check_when_align_2(
|
|
|
|
x: &Struct<WrapperWithAlign2<dyn Trait>>
|
|
|
|
) -> &WrapperWithAlign2<dyn Trait> {
|
|
|
|
// CHECK: [[X0:%[0-9]+]] = load [[USIZE]], {{.+}} !range [[RANGE_META]]
|
2022-03-01 15:07:46 -06:00
|
|
|
// CHECK: {{icmp|llvm.umax}}
|
2021-12-05 14:55:50 -06:00
|
|
|
// CHECK: ret
|
|
|
|
&x.dst
|
|
|
|
}
|
|
|
|
|
2022-12-08 00:30:07 -06:00
|
|
|
// CHECK-LABEL: @align_load_from_align_of_val
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn align_load_from_align_of_val(x: &dyn Trait) -> usize {
|
|
|
|
// CHECK: {{%[0-9]+}} = load [[USIZE]], {{.+}} !range [[RANGE_META]]
|
|
|
|
core::mem::align_of_val(x)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @align_load_from_vtable_align_intrinsic
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe fn align_load_from_vtable_align_intrinsic(x: &dyn Trait) -> usize {
|
|
|
|
let (data, vtable): (*const (), *const ()) = core::mem::transmute(x);
|
|
|
|
// CHECK: {{%[0-9]+}} = load [[USIZE]], {{.+}} !range [[RANGE_META]]
|
2022-12-08 18:33:14 -06:00
|
|
|
core::intrinsics::vtable_align(vtable)
|
2022-12-08 00:30:07 -06:00
|
|
|
}
|
|
|
|
|
2021-12-05 14:55:50 -06:00
|
|
|
// CHECK: [[RANGE_META]] = !{[[USIZE]] 1, [[USIZE]] 0}
|