blob: ef70444496e81a98458b2cdb8e36248c96bf7700 [file] [log] [blame]
Peter Collingbourne913869b2012-05-28 21:48:37 +00001; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s
2; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s
3
Justin Lebar50071f62017-01-15 16:54:57 +00004; CHECK-LABEL test_fabsf(
5define float @test_fabsf(float %f) {
6; CHECK: abs.f32
7 %x = call float @llvm.fabs.f32(float %f)
8 ret float %x
Peter Collingbourne913869b2012-05-28 21:48:37 +00009}
10
Justin Lebar50071f62017-01-15 16:54:57 +000011; CHECK-LABEL: test_fabs(
12define double @test_fabs(double %d) {
13; CHECK: abs.f64
14 %x = call double @llvm.fabs.f64(double %d)
15 ret double %x
Peter Collingbourne913869b2012-05-28 21:48:37 +000016}
17
Justin Lebar50071f62017-01-15 16:54:57 +000018; CHECK-LABEL: test_nvvm_sqrt(
Justin Holewinski48f4ad32013-05-21 16:51:30 +000019define float @test_nvvm_sqrt(float %a) {
Justin Lebar50071f62017-01-15 16:54:57 +000020; CHECK: sqrt.rn.f32
Justin Holewinski48f4ad32013-05-21 16:51:30 +000021 %val = call float @llvm.nvvm.sqrt.f(float %a)
22 ret float %val
23}
24
Justin Lebarc7d20122017-01-18 00:08:10 +000025; CHECK-LABEL: test_bitreverse32(
26define i32 @test_bitreverse32(i32 %a) {
27; CHECK: brev.b32
28 %val = call i32 @llvm.bitreverse.i32(i32 %a)
29 ret i32 %val
30}
31
32; CHECK-LABEL: test_bitreverse64(
33define i64 @test_bitreverse64(i64 %a) {
34; CHECK: brev.b64
35 %val = call i64 @llvm.bitreverse.i64(i64 %a)
36 ret i64 %val
37}
38
Justin Lebar1091a9f2017-01-18 00:08:27 +000039; CHECK-LABEL: test_popc32(
40define i32 @test_popc32(i32 %a) {
41; CHECK: popc.b32
42 %val = call i32 @llvm.ctpop.i32(i32 %a)
43 ret i32 %val
44}
45
46; CHECK-LABEL: test_popc64
47define i64 @test_popc64(i64 %a) {
48; CHECK: popc.b64
49; CHECK: cvt.u64.u32
50 %val = call i64 @llvm.ctpop.i64(i64 %a)
51 ret i64 %val
52}
53
54; NVPTX popc.b64 returns an i32 even though @llvm.ctpop.i64 returns an i64, so
55; if this function returns an i32, there's no need to do any type conversions
56; in the ptx.
57; CHECK-LABEL: test_popc64_trunc
58define i32 @test_popc64_trunc(i64 %a) {
59; CHECK: popc.b64
60; CHECK-NOT: cvt.
61 %val = call i64 @llvm.ctpop.i64(i64 %a)
62 %trunc = trunc i64 %val to i32
63 ret i32 %trunc
64}
65
66; llvm.ctpop.i16 is implemenented by converting to i32, running popc.b32, and
67; then converting back to i16.
68; CHECK-LABEL: test_popc16
69define void @test_popc16(i16 %a, i16* %b) {
70; CHECK: cvt.u32.u16
71; CHECK: popc.b32
72; CHECK: cvt.u16.u32
73 %val = call i16 @llvm.ctpop.i16(i16 %a)
74 store i16 %val, i16* %b
75 ret void
76}
77
78; If we call llvm.ctpop.i16 and then zext the result to i32, we shouldn't need
79; to do any conversions after calling popc.b32, because that returns an i32.
80; CHECK-LABEL: test_popc16_to_32
81define i32 @test_popc16_to_32(i16 %a) {
82; CHECK: cvt.u32.u16
83; CHECK: popc.b32
84; CHECK-NOT: cvt.
85 %val = call i16 @llvm.ctpop.i16(i16 %a)
86 %zext = zext i16 %val to i32
87 ret i32 %zext
88}
89
Peter Collingbourne913869b2012-05-28 21:48:37 +000090declare float @llvm.fabs.f32(float)
91declare double @llvm.fabs.f64(double)
Justin Holewinski48f4ad32013-05-21 16:51:30 +000092declare float @llvm.nvvm.sqrt.f(float)
Justin Lebarc7d20122017-01-18 00:08:10 +000093declare i32 @llvm.bitreverse.i32(i32)
94declare i64 @llvm.bitreverse.i64(i64)
Justin Lebar1091a9f2017-01-18 00:08:27 +000095declare i16 @llvm.ctpop.i16(i16)
96declare i32 @llvm.ctpop.i32(i32)
97declare i64 @llvm.ctpop.i64(i64)