Skip to content

Commit c2046c4

Browse files
committed
Add codegen tests for changed intrinsics
1 parent 7ce867f commit c2046c4

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

tests/codegen/intrinsics/ctlz.rs

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//@ compile-flags: -C no-prepopulate-passes
2+
3+
#![crate_type = "lib"]
4+
#![feature(core_intrinsics)]
5+
6+
use std::intrinsics::{ctlz, ctlz_nonzero};
7+
8+
// CHECK-LABEL: @ctlz_u16
9+
#[no_mangle]
10+
pub unsafe fn ctlz_u16(x: u16) -> u32 {
11+
// CHECK: %[[tmp:.*]] = call i16 @llvm.ctlz.i16(i16 %x, i1 false)
12+
// CHECK: zext i16 %[[tmp]] to i32
13+
ctlz(x)
14+
}
15+
16+
// CHECK-LABEL: @ctlz_nzu16
17+
#[no_mangle]
18+
pub unsafe fn ctlz_nzu16(x: u16) -> u32 {
19+
// CHECK: %[[tmp:.*]] = call i16 @llvm.ctlz.i16(i16 %x, i1 true)
20+
// CHECK: zext i16 %[[tmp]] to i32
21+
ctlz_nonzero(x)
22+
}
23+
24+
// CHECK-LABEL: @ctlz_u32
25+
#[no_mangle]
26+
pub unsafe fn ctlz_u32(x: u32) -> u32 {
27+
// CHECK: call i32 @llvm.ctlz.i32(i32 %x, i1 false)
28+
// CHECK-NOT: zext
29+
// CHECK-NOT: trunc
30+
ctlz(x)
31+
}
32+
33+
// CHECK-LABEL: @ctlz_nzu32
34+
#[no_mangle]
35+
pub unsafe fn ctlz_nzu32(x: u32) -> u32 {
36+
// CHECK: call i32 @llvm.ctlz.i32(i32 %x, i1 true)
37+
// CHECK-NOT: zext
38+
// CHECK-NOT: trunc
39+
ctlz_nonzero(x)
40+
}
41+
42+
// CHECK-LABEL: @ctlz_u64
43+
#[no_mangle]
44+
pub unsafe fn ctlz_u64(x: u64) -> u32 {
45+
// CHECK: %[[tmp:.*]] = call i64 @llvm.ctlz.i64(i64 %x, i1 false)
46+
// CHECK: trunc i64 %[[tmp]] to i32
47+
ctlz(x)
48+
}
49+
50+
// CHECK-LABEL: @ctlz_nzu64
51+
#[no_mangle]
52+
pub unsafe fn ctlz_nzu64(x: u64) -> u32 {
53+
// CHECK: %[[tmp:.*]] = call i64 @llvm.ctlz.i64(i64 %x, i1 true)
54+
// CHECK: trunc i64 %[[tmp]] to i32
55+
ctlz_nonzero(x)
56+
}

tests/codegen/intrinsics/ctpop.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@ compile-flags: -C no-prepopulate-passes
2+
3+
#![crate_type = "lib"]
4+
#![feature(core_intrinsics)]
5+
6+
use std::intrinsics::ctpop;
7+
8+
// CHECK-LABEL: @ctpop_u16
9+
#[no_mangle]
10+
pub unsafe fn ctpop_u16(x: u16) -> u32 {
11+
// CHECK: %[[tmp:.*]] = call i16 @llvm.ctpop.i16(i16 %x)
12+
// CHECK: zext i16 %[[tmp]] to i32
13+
ctpop(x)
14+
}
15+
16+
// CHECK-LABEL: @ctpop_u32
17+
#[no_mangle]
18+
pub unsafe fn ctpop_u32(x: u32) -> u32 {
19+
// CHECK: call i32 @llvm.ctpop.i32(i32 %x)
20+
// CHECK-NOT: zext
21+
// CHECK-NOT: trunc
22+
ctpop(x)
23+
}
24+
25+
// CHECK-LABEL: @ctpop_u64
26+
#[no_mangle]
27+
pub unsafe fn ctpop_u64(x: u64) -> u32 {
28+
// CHECK: %[[tmp:.*]] = call i64 @llvm.ctpop.i64(i64 %x)
29+
// CHECK: trunc i64 %[[tmp]] to i32
30+
ctpop(x)
31+
}
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@ compile-flags: -C no-prepopulate-passes
2+
3+
#![crate_type = "lib"]
4+
#![feature(core_intrinsics)]
5+
6+
use std::intrinsics::rotate_left;
7+
8+
// CHECK-LABEL: @rotate_left_u16
9+
#[no_mangle]
10+
pub unsafe fn rotate_left_u16(x: u16, shift: u32) -> u16 {
11+
// CHECK: %[[tmp:.*]] = trunc i32 %shift to i16
12+
// CHECK: call i16 @llvm.fshl.i16(i16 %x, i16 %x, i16 %[[tmp]])
13+
rotate_left(x, shift)
14+
}
15+
16+
// CHECK-LABEL: @rotate_left_u32
17+
#[no_mangle]
18+
pub unsafe fn rotate_left_u32(x: u32, shift: u32) -> u32 {
19+
// CHECK-NOT: trunc
20+
// CHECK-NOT: zext
21+
// CHECK: call i32 @llvm.fshl.i32(i32 %x, i32 %x, i32 %shift)
22+
rotate_left(x, shift)
23+
}
24+
25+
// CHECK-LABEL: @rotate_left_u64
26+
#[no_mangle]
27+
pub unsafe fn rotate_left_u64(x: u64, shift: u32) -> u64 {
28+
// CHECK: %[[tmp:.*]] = zext i32 %shift to i64
29+
// CHECK: call i64 @llvm.fshl.i64(i64 %x, i64 %x, i64 %[[tmp]])
30+
rotate_left(x, shift)
31+
}

0 commit comments

Comments
 (0)