1 ; RUN: llc < %s -march=nvptx -mcpu=sm_60 | FileCheck %s
2 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_60 | FileCheck %s
3 ; RUN: %if ptxas && !ptxas-12.0 %{ llc < %s -march=nvptx -mcpu=sm_60 | %ptxas-verify %}
4 ; RUN: %if ptxas %{ llc < %s -march=nvptx64 -mcpu=sm_60 | %ptxas-verify %}
6 ; CHECK-LABEL: test_fabsf(
7 define float @test_fabsf(float %f) {
9 %x = call float @llvm.fabs.f32(float %f)
13 ; CHECK-LABEL: test_fabs(
14 define double @test_fabs(double %d) {
16 %x = call double @llvm.fabs.f64(double %d)
20 ; CHECK-LABEL: test_nvvm_sqrt(
21 define float @test_nvvm_sqrt(float %a) {
23 %val = call float @llvm.nvvm.sqrt.f(float %a)
27 ; CHECK-LABEL: test_llvm_sqrt(
28 define float @test_llvm_sqrt(float %a) {
30 %val = call float @llvm.sqrt.f32(float %a)
34 ; CHECK-LABEL: test_bitreverse32(
35 define i32 @test_bitreverse32(i32 %a) {
37 %val = call i32 @llvm.bitreverse.i32(i32 %a)
41 ; CHECK-LABEL: test_bitreverse64(
42 define i64 @test_bitreverse64(i64 %a) {
44 %val = call i64 @llvm.bitreverse.i64(i64 %a)
48 ; CHECK-LABEL: test_popc32(
49 define i32 @test_popc32(i32 %a) {
51 %val = call i32 @llvm.ctpop.i32(i32 %a)
55 ; CHECK-LABEL: test_popc64
56 define i64 @test_popc64(i64 %a) {
59 %val = call i64 @llvm.ctpop.i64(i64 %a)
63 ; NVPTX popc.b64 returns an i32 even though @llvm.ctpop.i64 returns an i64, so
64 ; if this function returns an i32, there's no need to do any type conversions
66 ; CHECK-LABEL: test_popc64_trunc
67 define i32 @test_popc64_trunc(i64 %a) {
70 %val = call i64 @llvm.ctpop.i64(i64 %a)
71 %trunc = trunc i64 %val to i32
75 ; llvm.ctpop.i16 is implemenented by converting to i32, running popc.b32, and
76 ; then converting back to i16.
77 ; CHECK-LABEL: test_popc16
78 define void @test_popc16(i16 %a, ptr %b) {
82 %val = call i16 @llvm.ctpop.i16(i16 %a)
83 store i16 %val, ptr %b
87 ; If we call llvm.ctpop.i16 and then zext the result to i32, we shouldn't need
88 ; to do any conversions after calling popc.b32, because that returns an i32.
89 ; CHECK-LABEL: test_popc16_to_32
90 define i32 @test_popc16_to_32(i16 %a) {
94 %val = call i16 @llvm.ctpop.i16(i16 %a)
95 %zext = zext i16 %val to i32
99 ; Most of nvvm.read.ptx.sreg.* intrinsics always return the same value and may
101 ; CHECK-LABEL: test_tid
102 define i32 @test_tid() {
103 ; CHECK: mov.u32 %r{{.*}}, %tid.x;
104 %a = tail call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
105 ; CHECK-NOT: mov.u32 %r{{.*}}, %tid.x;
106 %b = tail call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
107 %ret = add i32 %a, %b
112 ; reading clock() or clock64() should not be CSE'd as each read may return
114 ; CHECK-LABEL: test_clock
115 define i32 @test_clock() {
116 ; CHECK: mov.u32 %r{{.*}}, %clock;
117 %a = tail call i32 @llvm.nvvm.read.ptx.sreg.clock()
118 ; CHECK: mov.u32 %r{{.*}}, %clock;
119 %b = tail call i32 @llvm.nvvm.read.ptx.sreg.clock()
120 %ret = add i32 %a, %b
125 ; CHECK-LABEL: test_clock64
126 define i64 @test_clock64() {
127 ; CHECK: mov.u64 %r{{.*}}, %clock64;
128 %a = tail call i64 @llvm.nvvm.read.ptx.sreg.clock64()
129 ; CHECK: mov.u64 %r{{.*}}, %clock64;
130 %b = tail call i64 @llvm.nvvm.read.ptx.sreg.clock64()
131 %ret = add i64 %a, %b
136 ; CHECK-LABEL: test_exit
137 define void @test_exit() {
139 call void @llvm.nvvm.exit()
143 ; CHECK-LABEL: test_globaltimer
144 define i64 @test_globaltimer() {
145 ; CHECK: mov.u64 %r{{.*}}, %globaltimer;
146 %a = tail call i64 @llvm.nvvm.read.ptx.sreg.globaltimer()
147 ; CHECK: mov.u64 %r{{.*}}, %globaltimer;
148 %b = tail call i64 @llvm.nvvm.read.ptx.sreg.globaltimer()
149 %ret = add i64 %a, %b
154 ; CHECK-LABEL: test_cyclecounter
155 define i64 @test_cyclecounter() {
156 ; CHECK: mov.u64 %r{{.*}}, %clock64;
157 %a = tail call i64 @llvm.readcyclecounter()
158 ; CHECK: mov.u64 %r{{.*}}, %clock64;
159 %b = tail call i64 @llvm.readcyclecounter()
160 %ret = add i64 %a, %b
165 ; CHECK-LABEL: test_steadycounter
166 define i64 @test_steadycounter() {
167 ; CHECK: mov.u64 %r{{.*}}, %globaltimer;
168 %a = tail call i64 @llvm.readsteadycounter()
169 ; CHECK: mov.u64 %r{{.*}}, %globaltimer;
170 %b = tail call i64 @llvm.readsteadycounter()
171 %ret = add i64 %a, %b
176 declare float @llvm.fabs.f32(float)
177 declare double @llvm.fabs.f64(double)
178 declare float @llvm.nvvm.sqrt.f(float)
179 declare float @llvm.sqrt.f32(float)
180 declare i32 @llvm.bitreverse.i32(i32)
181 declare i64 @llvm.bitreverse.i64(i64)
182 declare i16 @llvm.ctpop.i16(i16)
183 declare i32 @llvm.ctpop.i32(i32)
184 declare i64 @llvm.ctpop.i64(i64)
186 declare i32 @llvm.nvvm.read.ptx.sreg.tid.x()
187 declare i32 @llvm.nvvm.read.ptx.sreg.clock()
188 declare i64 @llvm.nvvm.read.ptx.sreg.clock64()
189 declare void @llvm.nvvm.exit()
190 declare i64 @llvm.nvvm.read.ptx.sreg.globaltimer()
191 declare i64 @llvm.readcyclecounter()
192 declare i64 @llvm.readsteadycounter()