1 ; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
3 ; CHECK: %[[#extinst_id:]] = OpExtInstImport "OpenCL.std"
5 ; CHECK: %[[#var0:]] = OpTypeFloat 16
6 ; CHECK: %[[#var1:]] = OpTypeFloat 32
7 ; CHECK: %[[#var2:]] = OpTypeFloat 64
8 ; CHECK: %[[#var3:]] = OpTypeVector %[[#var1]] 4
11 ; CHECK: %[[#]] = OpExtInst %[[#var0]] %[[#extinst_id]] fabs
12 ; CHECK: OpFunctionEnd
14 define spir_func half @TestFabs16(half %x) local_unnamed_addr {
16 %t = tail call half @llvm.fabs.f16(half %x)
21 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] fabs
22 ; CHECK: OpFunctionEnd
24 define spir_func float @TestFabs32(float %x) local_unnamed_addr {
26 %t = tail call float @llvm.fabs.f32(float %x)
31 ; CHECK: %[[#]] = OpExtInst %[[#var2]] %[[#extinst_id]] fabs
32 ; CHECK: OpFunctionEnd
34 define spir_func double @TestFabs64(double %x) local_unnamed_addr {
36 %t = tail call double @llvm.fabs.f64(double %x)
41 ; CHECK: %[[#]] = OpExtInst %[[#var3]] %[[#extinst_id]] fabs
42 ; CHECK: OpFunctionEnd
44 define spir_func <4 x float> @TestFabsVec(<4 x float> %x) local_unnamed_addr {
46 %t = tail call <4 x float> @llvm.fabs.v4f32(<4 x float> %x)
50 declare half @llvm.fabs.f16(half)
51 declare float @llvm.fabs.f32(float)
52 declare double @llvm.fabs.f64(double)
53 declare <4 x float> @llvm.fabs.v4f32(<4 x float>)
55 ;; We checked several types with fabs, but the type check works the same for
56 ;; all intrinsics being translated, so for the rest we'll just test one type.
59 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] ceil
60 ; CHECK: OpFunctionEnd
62 define spir_func float @TestCeil(float %x) local_unnamed_addr {
64 %t = tail call float @llvm.ceil.f32(float %x)
68 declare float @llvm.ceil.f32(float)
71 ; CHECK: %[[#x:]] = OpFunctionParameter %[[#]]
72 ; CHECK: %[[#n:]] = OpFunctionParameter %[[#]]
73 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] pown %[[#x]] %[[#n]]
74 ; CHECK: OpFunctionEnd
76 define spir_func float @TestPowi(float %x, i32 %n) local_unnamed_addr {
78 %t = tail call float @llvm.powi.f32(float %x, i32 %n)
82 declare float @llvm.powi.f32(float, i32)
85 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] sin
86 ; CHECK: OpFunctionEnd
88 define spir_func float @TestSin(float %x) local_unnamed_addr {
90 %t = tail call float @llvm.sin.f32(float %x)
94 declare float @llvm.sin.f32(float)
97 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] cos
98 ; CHECK: OpFunctionEnd
100 define spir_func float @TestCos(float %x) local_unnamed_addr {
102 %t = tail call float @llvm.cos.f32(float %x)
106 declare float @llvm.cos.f32(float)
109 ; CHECK: %[[#x:]] = OpFunctionParameter %[[#]]
110 ; CHECK: %[[#y:]] = OpFunctionParameter %[[#]]
111 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] pow %[[#x]] %[[#y]]
112 ; CHECK: OpFunctionEnd
114 define spir_func float @TestPow(float %x, float %y) local_unnamed_addr {
116 %t = tail call float @llvm.pow.f32(float %x, float %y)
120 declare float @llvm.pow.f32(float, float)
123 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] exp
124 ; CHECK: OpFunctionEnd
126 define spir_func float @TestExp(float %x) local_unnamed_addr {
128 %t = tail call float @llvm.exp.f32(float %x)
132 declare float @llvm.exp.f32(float)
135 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] exp2
136 ; CHECK: OpFunctionEnd
138 define spir_func float @TestExp2(float %x) local_unnamed_addr {
140 %t = tail call float @llvm.exp2.f32(float %x)
144 declare float @llvm.exp2.f32(float)
147 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] log
148 ; CHECK: OpFunctionEnd
150 define spir_func float @TestLog(float %x) local_unnamed_addr {
152 %t = tail call float @llvm.log.f32(float %x)
156 declare float @llvm.log.f32(float)
159 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] log10
160 ; CHECK: OpFunctionEnd
162 define spir_func float @TestLog10(float %x) local_unnamed_addr {
164 %t = tail call float @llvm.log10.f32(float %x)
168 declare float @llvm.log10.f32(float)
171 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] log2
172 ; CHECK: OpFunctionEnd
174 define spir_func float @TestLog2(float %x) local_unnamed_addr {
176 %t = tail call float @llvm.log2.f32(float %x)
180 declare float @llvm.log2.f32(float)
183 ; CHECK: %[[#x:]] = OpFunctionParameter %[[#]]
184 ; CHECK: %[[#y:]] = OpFunctionParameter %[[#]]
185 ; CHECK: %[[#res:]] = OpExtInst %[[#]] %[[#]] fmin %[[#x]] %[[#y]]
186 ; CHECK: OpReturnValue %[[#res]]
188 define spir_func float @TestMinNum(float %x, float %y) {
190 %t = call float @llvm.minnum.f32(float %x, float %y)
194 declare float @llvm.minnum.f32(float, float)
197 ; CHECK: %[[#x:]] = OpFunctionParameter %[[#]]
198 ; CHECK: %[[#y:]] = OpFunctionParameter %[[#]]
199 ; CHECK: %[[#res:]] = OpExtInst %[[#]] %[[#]] fmax %[[#x]] %[[#y]]
200 ; CHECK: OpReturnValue %[[#res]]
202 define spir_func float @TestMaxNum(float %x, float %y) {
204 %t = call float @llvm.maxnum.f32(float %x, float %y)
208 declare float @llvm.maxnum.f32(float, float)
211 ; CHECK: %[[#x:]] = OpFunctionParameter %[[#]]
212 ; CHECK: %[[#y:]] = OpFunctionParameter %[[#]]
213 ; CHECK: %[[#res:]] = OpExtInst %[[#]] %[[#]] fmin %[[#x]] %[[#y]]
214 ; CHECK: OpReturnValue %[[#res]]
216 define spir_func float @TestMinimum(float %x, float %y) {
218 %t = call float @llvm.minimum.f32(float %x, float %y)
222 declare float @llvm.minimum.f32(float, float)
225 ; CHECK: %[[#x:]] = OpFunctionParameter %[[#]]
226 ; CHECK: %[[#y:]] = OpFunctionParameter %[[#]]
227 ; CHECK: %[[#res:]] = OpExtInst %[[#]] %[[#]] fmax %[[#x]] %[[#y]]
228 ; CHECK: OpReturnValue %[[#res]]
230 define spir_func float @TestMaximum(float %x, float %y) {
232 %t = call float @llvm.maximum.f32(float %x, float %y)
236 declare float @llvm.maximum.f32(float, float)
239 ; CHECK: %[[#x:]] = OpFunctionParameter %[[#]]
240 ; CHECK: %[[#y:]] = OpFunctionParameter %[[#]]
241 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] copysign %[[#x]] %[[#y]]
242 ; CHECK: OpFunctionEnd
244 define spir_func float @TestCopysign(float %x, float %y) local_unnamed_addr {
246 %t = tail call float @llvm.copysign.f32(float %x, float %y)
250 declare float @llvm.copysign.f32(float, float)
253 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] floor
254 ; CHECK: OpFunctionEnd
256 define spir_func float @TestFloor(float %x) local_unnamed_addr {
258 %t = tail call float @llvm.floor.f32(float %x)
262 declare float @llvm.floor.f32(float)
265 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] trunc
266 ; CHECK: OpFunctionEnd
268 define spir_func float @TestTrunc(float %x) local_unnamed_addr {
270 %t = tail call float @llvm.trunc.f32(float %x)
274 declare float @llvm.trunc.f32(float)
277 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] rint
278 ; CHECK: OpFunctionEnd
280 define spir_func float @TestRint(float %x) local_unnamed_addr {
282 %t = tail call float @llvm.rint.f32(float %x)
286 declare float @llvm.rint.f32(float)
288 ;; It is intentional that nearbyint translates to rint.
290 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] rint
291 ; CHECK: OpFunctionEnd
293 define spir_func float @TestNearbyint(float %x) local_unnamed_addr {
295 %t = tail call float @llvm.nearbyint.f32(float %x)
299 declare float @llvm.nearbyint.f32(float)
302 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] round
303 ; CHECK: OpFunctionEnd
305 define spir_func float @TestRound(float %x) local_unnamed_addr {
307 %t = tail call float @llvm.round.f32(float %x)
311 declare float @llvm.round.f32(float)
313 ;; It is intentional that roundeven translates to rint.
315 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] rint
316 ; CHECK: OpFunctionEnd
318 define spir_func float @TestRoundEven(float %x) local_unnamed_addr {
320 %t = tail call float @llvm.roundeven.f32(float %x)
324 declare float @llvm.roundeven.f32(float)
327 ; CHECK: %[[#x:]] = OpFunctionParameter %[[#]]
328 ; CHECK: %[[#y:]] = OpFunctionParameter %[[#]]
329 ; CHECK: %[[#z:]] = OpFunctionParameter %[[#]]
330 ; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] fma %[[#x]] %[[#y]] %[[#z]]
331 ; CHECK: OpFunctionEnd
333 define spir_func float @TestFma(float %x, float %y, float %z) {
335 %t = tail call float @llvm.fma.f32(float %x, float %y, float %z)
339 declare float @llvm.fma.f32(float, float, float)