1 // compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0
5 use std::mem::MaybeUninit;
6 use std::num::NonZeroU16;
15 #[derive(Copy, Clone)]
22 pub struct Align16(u128);
24 // CHECK: @ptr_alignment_helper({}** {{.*}}align [[PTR_ALIGNMENT:[0-9]+]]
26 pub fn ptr_alignment_helper(x: &&()) {}
28 // CHECK-LABEL: @load_ref
30 pub fn load_ref<'a>(x: &&'a i32) -> &'a i32 {
31 // CHECK: load i32*, i32** %x, align [[PTR_ALIGNMENT]], !nonnull !{{[0-9]+}}, !align ![[ALIGN_4_META:[0-9]+]], !noundef !{{[0-9]+}}
35 // CHECK-LABEL: @load_ref_higher_alignment
37 pub fn load_ref_higher_alignment<'a>(x: &&'a Align16) -> &'a Align16 {
38 // CHECK: load {{%Align16|i128}}*, {{%Align16|i128}}** %x, align [[PTR_ALIGNMENT]], !nonnull !{{[0-9]+}}, !align ![[ALIGN_16_META:[0-9]+]], !noundef !{{[0-9]+}}
42 // CHECK-LABEL: @load_scalar_pair
44 pub fn load_scalar_pair<'a>(x: &(&'a i32, &'a Align16)) -> (&'a i32, &'a Align16) {
45 // CHECK: load i32*, i32** %{{.+}}, align [[PTR_ALIGNMENT]], !nonnull !{{[0-9]+}}, !align ![[ALIGN_4_META]], !noundef !{{[0-9]+}}
46 // CHECK: load i64*, i64** %{{.+}}, align [[PTR_ALIGNMENT]], !nonnull !{{[0-9]+}}, !align ![[ALIGN_16_META]], !noundef !{{[0-9]+}}
50 // CHECK-LABEL: @load_raw_pointer
52 pub fn load_raw_pointer<'a>(x: &*const i32) -> *const i32 {
53 // loaded raw pointer should not have !nonnull, !align, or !noundef metadata
54 // CHECK: load i32*, i32** %x, align [[PTR_ALIGNMENT]]{{$}}
58 // CHECK-LABEL: @load_box
60 pub fn load_box<'a>(x: Box<Box<i32>>) -> Box<i32> {
61 // CHECK: load i32*, i32** %x, align [[PTR_ALIGNMENT]], !nonnull !{{[0-9]+}}, !align ![[ALIGN_4_META]], !noundef !{{[0-9]+}}
65 // CHECK-LABEL: @load_bool
67 pub fn load_bool(x: &bool) -> bool {
68 // CHECK: load i8, i8* %x, align 1, !range ![[BOOL_RANGE:[0-9]+]], !noundef !{{[0-9]+}}
72 // CHECK-LABEL: @load_maybeuninit_bool
74 pub fn load_maybeuninit_bool(x: &MaybeUninit<bool>) -> MaybeUninit<bool> {
75 // CHECK: load i8, i8* %x, align 1{{$}}
79 // CHECK-LABEL: @load_enum_bool
81 pub fn load_enum_bool(x: &MyBool) -> MyBool {
82 // CHECK: load i8, i8* %x, align 1, !range ![[BOOL_RANGE]], !noundef !{{[0-9]+}}
86 // CHECK-LABEL: @load_maybeuninit_enum_bool
88 pub fn load_maybeuninit_enum_bool(x: &MaybeUninit<MyBool>) -> MaybeUninit<MyBool> {
89 // CHECK: load i8, i8* %x, align 1{{$}}
93 // CHECK-LABEL: @load_int
95 pub fn load_int(x: &u16) -> u16 {
96 // CHECK: load i16, i16* %x, align 2{{$}}
100 // CHECK-LABEL: @load_nonzero_int
102 pub fn load_nonzero_int(x: &NonZeroU16) -> NonZeroU16 {
103 // CHECK: load i16, i16* %x, align 2, !range ![[NONZEROU16_RANGE:[0-9]+]], !noundef !{{[0-9]+}}
107 // CHECK-LABEL: @load_option_nonzero_int
109 pub fn load_option_nonzero_int(x: &Option<NonZeroU16>) -> Option<NonZeroU16> {
110 // CHECK: load i16, i16* %x, align 2{{$}}
114 // CHECK-LABEL: @borrow
116 pub fn borrow(x: &i32) -> &i32 {
117 // CHECK: load {{(i32\*, )?}}i32** %x{{.*}}, !nonnull
118 &x; // keep variable in an alloca
122 // CHECK-LABEL: @_box
124 pub fn _box(x: Box<i32>) -> i32 {
125 // CHECK: load {{(i32\*, )?}}i32** %x{{.*}}, !nonnull
129 // CHECK-LABEL: small_array_alignment
130 // The array is loaded as i32, but its alignment is lower, go with 1 byte to avoid target
131 // dependent alignment
133 pub fn small_array_alignment(x: [i8; 4]) -> [i8; 4] {
134 // CHECK: [[VAR:%[0-9]+]] = load {{(i32, )?}}i32* %{{.*}}, align 1
135 // CHECK: ret i32 [[VAR]]
139 // CHECK-LABEL: small_struct_alignment
140 // The struct is loaded as i32, but its alignment is lower, go with 1 byte to avoid target
141 // dependent alignment
143 pub fn small_struct_alignment(x: Bytes) -> Bytes {
144 // CHECK: [[VAR:%[0-9]+]] = load {{(i32, )?}}i32* %{{.*}}, align 1
145 // CHECK: ret i32 [[VAR]]
149 // CHECK-DAG: ![[BOOL_RANGE]] = !{i8 0, i8 2}
150 // CHECK-DAG: ![[NONZEROU16_RANGE]] = !{i16 1, i16 0}
151 // CHECK-DAG: ![[ALIGN_4_META]] = !{i64 4}
152 // CHECK-DAG: ![[ALIGN_16_META]] = !{i64 16}