]>
Commit | Line | Data |
---|---|---|
a2a8927a XL |
1 | // compile-flags: -O |
2 | ||
3 | #![crate_type = "lib"] | |
4 | ||
5 | // This test checks that we annotate alignment loads from vtables with nonzero range metadata, | |
6 | // and that this allows LLVM to eliminate redundant `align >= 1` checks. | |
7 | ||
8 | pub trait Trait { | |
9 | fn f(&self); | |
10 | } | |
11 | ||
12 | pub struct WrapperWithAlign1<T: ?Sized> { x: u8, y: T } | |
13 | ||
14 | pub struct WrapperWithAlign2<T: ?Sized> { x: u16, y: T } | |
15 | ||
16 | pub struct Struct<W: ?Sized> { | |
17 | _field: i8, | |
18 | dst: W, | |
19 | } | |
20 | ||
21 | // CHECK-LABEL: @eliminates_runtime_check_when_align_1 | |
22 | #[no_mangle] | |
23 | pub fn eliminates_runtime_check_when_align_1( | |
24 | x: &Struct<WrapperWithAlign1<dyn Trait>> | |
25 | ) -> &WrapperWithAlign1<dyn Trait> { | |
26 | // CHECK: load [[USIZE:i[0-9]+]], {{.+}} !range [[RANGE_META:![0-9]+]] | |
ee023bcb | 27 | // CHECK-NOT: llvm.umax |
a2a8927a XL |
28 | // CHECK-NOT: icmp |
29 | // CHECK-NOT: select | |
30 | // CHECK: ret | |
31 | &x.dst | |
32 | } | |
33 | ||
34 | // CHECK-LABEL: @does_not_eliminate_runtime_check_when_align_2 | |
35 | #[no_mangle] | |
36 | pub fn does_not_eliminate_runtime_check_when_align_2( | |
37 | x: &Struct<WrapperWithAlign2<dyn Trait>> | |
38 | ) -> &WrapperWithAlign2<dyn Trait> { | |
39 | // CHECK: [[X0:%[0-9]+]] = load [[USIZE]], {{.+}} !range [[RANGE_META]] | |
ee023bcb | 40 | // CHECK: {{icmp|llvm.umax}} |
a2a8927a XL |
41 | // CHECK: ret |
42 | &x.dst | |
43 | } | |
44 | ||
45 | // CHECK: [[RANGE_META]] = !{[[USIZE]] 1, [[USIZE]] 0} |