2 // min-llvm-version: 15.0 (LLVM 13 in CI does this differently from submodule LLVM)
3 // ignore-debug (because unchecked is checked in debug)
6 #![feature(unchecked_math)]
8 // CHECK-LABEL: @unchecked_shl_unsigned_same
10 pub unsafe fn unchecked_shl_unsigned_same(a: u32, b: u32) -> u32 {
12 // CHECK: shl i32 %a, %b
17 // CHECK-LABEL: @unchecked_shl_unsigned_smaller
19 pub unsafe fn unchecked_shl_unsigned_smaller(a: u16, b: u32) -> u16 {
20 // This uses -DAG to avoid failing on irrelevant reorderings,
21 // like emitting the truncation earlier.
23 // CHECK-DAG: %[[INRANGE:.+]] = icmp ult i32 %b, 65536
24 // CHECK-DAG: tail call void @llvm.assume(i1 %[[INRANGE]])
25 // CHECK-DAG: %[[TRUNC:.+]] = trunc i32 %b to i16
26 // CHECK-DAG: shl i16 %a, %[[TRUNC]]
30 // CHECK-LABEL: @unchecked_shl_unsigned_bigger
32 pub unsafe fn unchecked_shl_unsigned_bigger(a: u64, b: u32) -> u64 {
33 // CHECK: %[[EXT:.+]] = zext i32 %b to i64
34 // CHECK: shl i64 %a, %[[EXT]]
38 // CHECK-LABEL: @unchecked_shr_signed_same
40 pub unsafe fn unchecked_shr_signed_same(a: i32, b: u32) -> i32 {
42 // CHECK: ashr i32 %a, %b
47 // CHECK-LABEL: @unchecked_shr_signed_smaller
49 pub unsafe fn unchecked_shr_signed_smaller(a: i16, b: u32) -> i16 {
50 // This uses -DAG to avoid failing on irrelevant reorderings,
51 // like emitting the truncation earlier.
53 // CHECK-DAG: %[[INRANGE:.+]] = icmp ult i32 %b, 32768
54 // CHECK-DAG: tail call void @llvm.assume(i1 %[[INRANGE]])
55 // CHECK-DAG: %[[TRUNC:.+]] = trunc i32 %b to i16
56 // CHECK-DAG: ashr i16 %a, %[[TRUNC]]
60 // CHECK-LABEL: @unchecked_shr_signed_bigger
62 pub unsafe fn unchecked_shr_signed_bigger(a: i64, b: u32) -> i64 {
63 // CHECK: %[[EXT:.+]] = zext i32 %b to i64
64 // CHECK: ashr i64 %a, %[[EXT]]