diff --git a/tests/codegen/intrinsics/ctlz.rs b/tests/codegen/intrinsics/ctlz.rs new file mode 100644 index 00000000000..0d54d21ce12 --- /dev/null +++ b/tests/codegen/intrinsics/ctlz.rs @@ -0,0 +1,56 @@ +//@ compile-flags: -C no-prepopulate-passes + +#![crate_type = "lib"] +#![feature(core_intrinsics)] + +use std::intrinsics::{ctlz, ctlz_nonzero}; + +// CHECK-LABEL: @ctlz_u16 +#[no_mangle] +pub unsafe fn ctlz_u16(x: u16) -> u32 { + // CHECK: %[[tmp:.*]] = call i16 @llvm.ctlz.i16(i16 %x, i1 false) + // CHECK: zext i16 %[[tmp]] to i32 + ctlz(x) +} + +// CHECK-LABEL: @ctlz_nzu16 +#[no_mangle] +pub unsafe fn ctlz_nzu16(x: u16) -> u32 { + // CHECK: %[[tmp:.*]] = call i16 @llvm.ctlz.i16(i16 %x, i1 true) + // CHECK: zext i16 %[[tmp]] to i32 + ctlz_nonzero(x) +} + +// CHECK-LABEL: @ctlz_u32 +#[no_mangle] +pub unsafe fn ctlz_u32(x: u32) -> u32 { + // CHECK: call i32 @llvm.ctlz.i32(i32 %x, i1 false) + // CHECK-NOT: zext + // CHECK-NOT: trunc + ctlz(x) +} + +// CHECK-LABEL: @ctlz_nzu32 +#[no_mangle] +pub unsafe fn ctlz_nzu32(x: u32) -> u32 { + // CHECK: call i32 @llvm.ctlz.i32(i32 %x, i1 true) + // CHECK-NOT: zext + // CHECK-NOT: trunc + ctlz_nonzero(x) +} + +// CHECK-LABEL: @ctlz_u64 +#[no_mangle] +pub unsafe fn ctlz_u64(x: u64) -> u32 { + // CHECK: %[[tmp:.*]] = call i64 @llvm.ctlz.i64(i64 %x, i1 false) + // CHECK: trunc i64 %[[tmp]] to i32 + ctlz(x) +} + +// CHECK-LABEL: @ctlz_nzu64 +#[no_mangle] +pub unsafe fn ctlz_nzu64(x: u64) -> u32 { + // CHECK: %[[tmp:.*]] = call i64 @llvm.ctlz.i64(i64 %x, i1 true) + // CHECK: trunc i64 %[[tmp]] to i32 + ctlz_nonzero(x) +} diff --git a/tests/codegen/intrinsics/ctpop.rs b/tests/codegen/intrinsics/ctpop.rs new file mode 100644 index 00000000000..f4043325de9 --- /dev/null +++ b/tests/codegen/intrinsics/ctpop.rs @@ -0,0 +1,31 @@ +//@ compile-flags: -C no-prepopulate-passes + +#![crate_type = "lib"] +#![feature(core_intrinsics)] + +use std::intrinsics::ctpop; + +// CHECK-LABEL: @ctpop_u16 +#[no_mangle] +pub unsafe fn ctpop_u16(x: u16) -> u32 { + // CHECK: %[[tmp:.*]] = call i16 @llvm.ctpop.i16(i16 %x) + // CHECK: zext i16 %[[tmp]] to i32 + ctpop(x) +} + +// CHECK-LABEL: @ctpop_u32 +#[no_mangle] +pub unsafe fn ctpop_u32(x: u32) -> u32 { + // CHECK: call i32 @llvm.ctpop.i32(i32 %x) + // CHECK-NOT: zext + // CHECK-NOT: trunc + ctpop(x) +} + +// CHECK-LABEL: @ctpop_u64 +#[no_mangle] +pub unsafe fn ctpop_u64(x: u64) -> u32 { + // CHECK: %[[tmp:.*]] = call i64 @llvm.ctpop.i64(i64 %x) + // CHECK: trunc i64 %[[tmp]] to i32 + ctpop(x) +} diff --git a/tests/codegen/intrinsics/rotate_left.rs b/tests/codegen/intrinsics/rotate_left.rs new file mode 100644 index 00000000000..4f6c5cbaed6 --- /dev/null +++ b/tests/codegen/intrinsics/rotate_left.rs @@ -0,0 +1,31 @@ +//@ compile-flags: -C no-prepopulate-passes + +#![crate_type = "lib"] +#![feature(core_intrinsics)] + +use std::intrinsics::rotate_left; + +// CHECK-LABEL: @rotate_left_u16 +#[no_mangle] +pub unsafe fn rotate_left_u16(x: u16, shift: u32) -> u16 { + // CHECK: %[[tmp:.*]] = trunc i32 %shift to i16 + // CHECK: call i16 @llvm.fshl.i16(i16 %x, i16 %x, i16 %[[tmp]]) + rotate_left(x, shift) +} + +// CHECK-LABEL: @rotate_left_u32 +#[no_mangle] +pub unsafe fn rotate_left_u32(x: u32, shift: u32) -> u32 { + // CHECK-NOT: trunc + // CHECK-NOT: zext + // CHECK: call i32 @llvm.fshl.i32(i32 %x, i32 %x, i32 %shift) + rotate_left(x, shift) +} + +// CHECK-LABEL: @rotate_left_u64 +#[no_mangle] +pub unsafe fn rotate_left_u64(x: u64, shift: u32) -> u64 { + // CHECK: %[[tmp:.*]] = zext i32 %shift to i64 + // CHECK: call i64 @llvm.fshl.i64(i64 %x, i64 %x, i64 %[[tmp]]) + rotate_left(x, shift) +}