| 1 |
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s |
| 2 |
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %} |
| 3 |
|
| 4 |
; CHECK: %[[#extinst_id:]] = OpExtInstImport "OpenCL.std" |
| 5 |
|
| 6 |
; CHECK: %[[#var0:]] = OpTypeFloat 16 |
| 7 |
; CHECK: %[[#var1:]] = OpTypeFloat 32 |
| 8 |
; CHECK: %[[#var2:]] = OpTypeFloat 64 |
| 9 |
; CHECK: %[[#var3:]] = OpTypeVector %[[#var1]] 4 |
| 10 |
|
| 11 |
; CHECK: OpFunction |
| 12 |
; CHECK: %[[#]] = OpExtInst %[[#var0]] %[[#extinst_id]] fabs |
| 13 |
; CHECK: OpFunctionEnd |
| 14 |
|
| 15 |
define spir_func half @TestFabs16(half %x) local_unnamed_addr { |
| 16 |
entry: |
| 17 |
%t = tail call half @llvm.fabs.f16(half %x) |
| 18 |
ret half %t |
| 19 |
} |
| 20 |
|
| 21 |
; CHECK: OpFunction |
| 22 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] fabs |
| 23 |
; CHECK: OpFunctionEnd |
| 24 |
|
| 25 |
define spir_func float @TestFabs32(float %x) local_unnamed_addr { |
| 26 |
entry: |
| 27 |
%t = tail call float @llvm.fabs.f32(float %x) |
| 28 |
ret float %t |
| 29 |
} |
| 30 |
|
| 31 |
; CHECK: OpFunction |
| 32 |
; CHECK: %[[#]] = OpExtInst %[[#var2]] %[[#extinst_id]] fabs |
| 33 |
; CHECK: OpFunctionEnd |
| 34 |
|
| 35 |
define spir_func double @TestFabs64(double %x) local_unnamed_addr { |
| 36 |
entry: |
| 37 |
%t = tail call double @llvm.fabs.f64(double %x) |
| 38 |
ret double %t |
| 39 |
} |
| 40 |
|
| 41 |
; CHECK: OpFunction |
| 42 |
; CHECK: %[[#]] = OpExtInst %[[#var3]] %[[#extinst_id]] fabs |
| 43 |
; CHECK: OpFunctionEnd |
| 44 |
|
| 45 |
define spir_func <4 x float> @TestFabsVec(<4 x float> %x) local_unnamed_addr { |
| 46 |
entry: |
| 47 |
%t = tail call <4 x float> @llvm.fabs.v4f32(<4 x float> %x) |
| 48 |
ret <4 x float> %t |
| 49 |
} |
| 50 |
|
| 51 |
declare half @llvm.fabs.f16(half) |
| 52 |
declare float @llvm.fabs.f32(float) |
| 53 |
declare double @llvm.fabs.f64(double) |
| 54 |
declare <4 x float> @llvm.fabs.v4f32(<4 x float>) |
| 55 |
|
| 56 |
;; We checked several types with fabs, but the type check works the same for |
| 57 |
;; all intrinsics being translated, so for the rest we'll just test one type. |
| 58 |
|
| 59 |
; CHECK: OpFunction |
| 60 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] ceil |
| 61 |
; CHECK: OpFunctionEnd |
| 62 |
|
| 63 |
define spir_func float @TestCeil(float %x) local_unnamed_addr { |
| 64 |
entry: |
| 65 |
%t = tail call float @llvm.ceil.f32(float %x) |
| 66 |
ret float %t |
| 67 |
} |
| 68 |
|
| 69 |
declare float @llvm.ceil.f32(float) |
| 70 |
|
| 71 |
; CHECK: OpFunction |
| 72 |
; CHECK: %[[#x:]] = OpFunctionParameter %[[#]] |
| 73 |
; CHECK: %[[#n:]] = OpFunctionParameter %[[#]] |
| 74 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] pown %[[#x]] %[[#n]] |
| 75 |
; CHECK: OpFunctionEnd |
| 76 |
|
| 77 |
define spir_func float @TestPowi(float %x, i32 %n) local_unnamed_addr { |
| 78 |
entry: |
| 79 |
%t = tail call float @llvm.powi.f32(float %x, i32 %n) |
| 80 |
ret float %t |
| 81 |
} |
| 82 |
|
| 83 |
declare float @llvm.powi.f32(float, i32) |
| 84 |
|
| 85 |
; CHECK: OpFunction |
| 86 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] sin |
| 87 |
; CHECK: OpFunctionEnd |
| 88 |
|
| 89 |
define spir_func float @TestSin(float %x) local_unnamed_addr { |
| 90 |
entry: |
| 91 |
%t = tail call float @llvm.sin.f32(float %x) |
| 92 |
ret float %t |
| 93 |
} |
| 94 |
|
| 95 |
declare float @llvm.sin.f32(float) |
| 96 |
|
| 97 |
; CHECK: OpFunction |
| 98 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] cos |
| 99 |
; CHECK: OpFunctionEnd |
| 100 |
|
| 101 |
define spir_func float @TestCos(float %x) local_unnamed_addr { |
| 102 |
entry: |
| 103 |
%t = tail call float @llvm.cos.f32(float %x) |
| 104 |
ret float %t |
| 105 |
} |
| 106 |
|
| 107 |
declare float @llvm.cos.f32(float) |
| 108 |
|
| 109 |
; CHECK: OpFunction |
| 110 |
; CHECK: %[[#x:]] = OpFunctionParameter %[[#]] |
| 111 |
; CHECK: %[[#y:]] = OpFunctionParameter %[[#]] |
| 112 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] pow %[[#x]] %[[#y]] |
| 113 |
; CHECK: OpFunctionEnd |
| 114 |
|
| 115 |
define spir_func float @TestPow(float %x, float %y) local_unnamed_addr { |
| 116 |
entry: |
| 117 |
%t = tail call float @llvm.pow.f32(float %x, float %y) |
| 118 |
ret float %t |
| 119 |
} |
| 120 |
|
| 121 |
declare float @llvm.pow.f32(float, float) |
| 122 |
|
| 123 |
; CHECK: OpFunction |
| 124 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] exp |
| 125 |
; CHECK: OpFunctionEnd |
| 126 |
|
| 127 |
define spir_func float @TestExp(float %x) local_unnamed_addr { |
| 128 |
entry: |
| 129 |
%t = tail call float @llvm.exp.f32(float %x) |
| 130 |
ret float %t |
| 131 |
} |
| 132 |
|
| 133 |
declare float @llvm.exp.f32(float) |
| 134 |
|
| 135 |
; CHECK: OpFunction |
| 136 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] exp2 |
| 137 |
; CHECK: OpFunctionEnd |
| 138 |
|
| 139 |
define spir_func float @TestExp2(float %x) local_unnamed_addr { |
| 140 |
entry: |
| 141 |
%t = tail call float @llvm.exp2.f32(float %x) |
| 142 |
ret float %t |
| 143 |
} |
| 144 |
|
| 145 |
declare float @llvm.exp2.f32(float) |
| 146 |
|
| 147 |
; CHECK: OpFunction |
| 148 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] log |
| 149 |
; CHECK: OpFunctionEnd |
| 150 |
|
| 151 |
define spir_func float @TestLog(float %x) local_unnamed_addr { |
| 152 |
entry: |
| 153 |
%t = tail call float @llvm.log.f32(float %x) |
| 154 |
ret float %t |
| 155 |
} |
| 156 |
|
| 157 |
declare float @llvm.log.f32(float) |
| 158 |
|
| 159 |
; CHECK: OpFunction |
| 160 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] log10 |
| 161 |
; CHECK: OpFunctionEnd |
| 162 |
|
| 163 |
define spir_func float @TestLog10(float %x) local_unnamed_addr { |
| 164 |
entry: |
| 165 |
%t = tail call float @llvm.log10.f32(float %x) |
| 166 |
ret float %t |
| 167 |
} |
| 168 |
|
| 169 |
declare float @llvm.log10.f32(float) |
| 170 |
|
| 171 |
; CHECK: OpFunction |
| 172 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] log2 |
| 173 |
; CHECK: OpFunctionEnd |
| 174 |
|
| 175 |
define spir_func float @TestLog2(float %x) local_unnamed_addr { |
| 176 |
entry: |
| 177 |
%t = tail call float @llvm.log2.f32(float %x) |
| 178 |
ret float %t |
| 179 |
} |
| 180 |
|
| 181 |
declare float @llvm.log2.f32(float) |
| 182 |
|
| 183 |
; CHECK: OpFunction |
| 184 |
; CHECK: %[[#x:]] = OpFunctionParameter %[[#]] |
| 185 |
; CHECK: %[[#y:]] = OpFunctionParameter %[[#]] |
| 186 |
; CHECK: %[[#res:]] = OpExtInst %[[#]] %[[#]] fmin %[[#x]] %[[#y]] |
| 187 |
; CHECK: OpReturnValue %[[#res]] |
| 188 |
|
| 189 |
define spir_func float @TestMinNum(float %x, float %y) { |
| 190 |
entry: |
| 191 |
%t = call float @llvm.minnum.f32(float %x, float %y) |
| 192 |
ret float %t |
| 193 |
} |
| 194 |
|
| 195 |
declare float @llvm.minnum.f32(float, float) |
| 196 |
|
| 197 |
; CHECK: OpFunction |
| 198 |
; CHECK: %[[#x:]] = OpFunctionParameter %[[#]] |
| 199 |
; CHECK: %[[#y:]] = OpFunctionParameter %[[#]] |
| 200 |
; CHECK: %[[#res:]] = OpExtInst %[[#]] %[[#]] fmax %[[#x]] %[[#y]] |
| 201 |
; CHECK: OpReturnValue %[[#res]] |
| 202 |
|
| 203 |
define spir_func float @TestMaxNum(float %x, float %y) { |
| 204 |
entry: |
| 205 |
%t = call float @llvm.maxnum.f32(float %x, float %y) |
| 206 |
ret float %t |
| 207 |
} |
| 208 |
|
| 209 |
declare float @llvm.maxnum.f32(float, float) |
| 210 |
|
| 211 |
; CHECK: OpFunction |
| 212 |
; CHECK: %[[#x:]] = OpFunctionParameter %[[#]] |
| 213 |
; CHECK: %[[#y:]] = OpFunctionParameter %[[#]] |
| 214 |
; CHECK: %[[#res:]] = OpExtInst %[[#]] %[[#]] fmin %[[#x]] %[[#y]] |
| 215 |
; CHECK: OpReturnValue %[[#res]] |
| 216 |
|
| 217 |
define spir_func float @TestMinimum(float %x, float %y) { |
| 218 |
entry: |
| 219 |
%t = call float @llvm.minimum.f32(float %x, float %y) |
| 220 |
ret float %t |
| 221 |
} |
| 222 |
|
| 223 |
declare float @llvm.minimum.f32(float, float) |
| 224 |
|
| 225 |
; CHECK: OpFunction |
| 226 |
; CHECK: %[[#x:]] = OpFunctionParameter %[[#]] |
| 227 |
; CHECK: %[[#y:]] = OpFunctionParameter %[[#]] |
| 228 |
; CHECK: %[[#res:]] = OpExtInst %[[#]] %[[#]] fmax %[[#x]] %[[#y]] |
| 229 |
; CHECK: OpReturnValue %[[#res]] |
| 230 |
|
| 231 |
define spir_func float @TestMaximum(float %x, float %y) { |
| 232 |
entry: |
| 233 |
%t = call float @llvm.maximum.f32(float %x, float %y) |
| 234 |
ret float %t |
| 235 |
} |
| 236 |
|
| 237 |
declare float @llvm.maximum.f32(float, float) |
| 238 |
|
| 239 |
; CHECK: OpFunction |
| 240 |
; CHECK: %[[#x:]] = OpFunctionParameter %[[#]] |
| 241 |
; CHECK: %[[#y:]] = OpFunctionParameter %[[#]] |
| 242 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] copysign %[[#x]] %[[#y]] |
| 243 |
; CHECK: OpFunctionEnd |
| 244 |
|
| 245 |
define spir_func float @TestCopysign(float %x, float %y) local_unnamed_addr { |
| 246 |
entry: |
| 247 |
%t = tail call float @llvm.copysign.f32(float %x, float %y) |
| 248 |
ret float %t |
| 249 |
} |
| 250 |
|
| 251 |
declare float @llvm.copysign.f32(float, float) |
| 252 |
|
| 253 |
; CHECK: OpFunction |
| 254 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] floor |
| 255 |
; CHECK: OpFunctionEnd |
| 256 |
|
| 257 |
define spir_func float @TestFloor(float %x) local_unnamed_addr { |
| 258 |
entry: |
| 259 |
%t = tail call float @llvm.floor.f32(float %x) |
| 260 |
ret float %t |
| 261 |
} |
| 262 |
|
| 263 |
declare float @llvm.floor.f32(float) |
| 264 |
|
| 265 |
; CHECK: OpFunction |
| 266 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] trunc |
| 267 |
; CHECK: OpFunctionEnd |
| 268 |
|
| 269 |
define spir_func float @TestTrunc(float %x) local_unnamed_addr { |
| 270 |
entry: |
| 271 |
%t = tail call float @llvm.trunc.f32(float %x) |
| 272 |
ret float %t |
| 273 |
} |
| 274 |
|
| 275 |
declare float @llvm.trunc.f32(float) |
| 276 |
|
| 277 |
; CHECK: OpFunction |
| 278 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] rint |
| 279 |
; CHECK: OpFunctionEnd |
| 280 |
|
| 281 |
define spir_func float @TestRint(float %x) local_unnamed_addr { |
| 282 |
entry: |
| 283 |
%t = tail call float @llvm.rint.f32(float %x) |
| 284 |
ret float %t |
| 285 |
} |
| 286 |
|
| 287 |
declare float @llvm.rint.f32(float) |
| 288 |
|
| 289 |
;; It is intentional that nearbyint translates to rint. |
| 290 |
; CHECK: OpFunction |
| 291 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] rint |
| 292 |
; CHECK: OpFunctionEnd |
| 293 |
|
| 294 |
define spir_func float @TestNearbyint(float %x) local_unnamed_addr { |
| 295 |
entry: |
| 296 |
%t = tail call float @llvm.nearbyint.f32(float %x) |
| 297 |
ret float %t |
| 298 |
} |
| 299 |
|
| 300 |
declare float @llvm.nearbyint.f32(float) |
| 301 |
|
| 302 |
; CHECK: OpFunction |
| 303 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] round |
| 304 |
; CHECK: OpFunctionEnd |
| 305 |
|
| 306 |
define spir_func float @TestRound(float %x) local_unnamed_addr { |
| 307 |
entry: |
| 308 |
%t = tail call float @llvm.round.f32(float %x) |
| 309 |
ret float %t |
| 310 |
} |
| 311 |
|
| 312 |
declare float @llvm.round.f32(float) |
| 313 |
|
| 314 |
;; It is intentional that roundeven translates to rint. |
| 315 |
; CHECK: OpFunction |
| 316 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] rint |
| 317 |
; CHECK: OpFunctionEnd |
| 318 |
|
| 319 |
define spir_func float @TestRoundEven(float %x) local_unnamed_addr { |
| 320 |
entry: |
| 321 |
%t = tail call float @llvm.roundeven.f32(float %x) |
| 322 |
ret float %t |
| 323 |
} |
| 324 |
|
| 325 |
declare float @llvm.roundeven.f32(float) |
| 326 |
|
| 327 |
; CHECK: OpFunction |
| 328 |
; CHECK: %[[#x:]] = OpFunctionParameter %[[#]] |
| 329 |
; CHECK: %[[#y:]] = OpFunctionParameter %[[#]] |
| 330 |
; CHECK: %[[#z:]] = OpFunctionParameter %[[#]] |
| 331 |
; CHECK: %[[#]] = OpExtInst %[[#var1]] %[[#extinst_id]] fma %[[#x]] %[[#y]] %[[#z]] |
| 332 |
; CHECK: OpFunctionEnd |
| 333 |
|
| 334 |
define spir_func float @TestFma(float %x, float %y, float %z) { |
| 335 |
entry: |
| 336 |
%t = tail call float @llvm.fma.f32(float %x, float %y, float %z) |
| 337 |
ret float %t |
| 338 |
} |
| 339 |
|
| 340 |
declare float @llvm.fma.f32(float, float, float) |
| 341 |
|
| 342 |
; CHECK: OpFunction |
| 343 |
; CHECK: %[[#d:]] = OpFunctionParameter %[[#]] |
| 344 |
; CHECK: %[[#fracPtr:]] = OpFunctionParameter %[[#]] |
| 345 |
; CHECK: %[[#integralPtr:]] = OpFunctionParameter %[[#]] |
| 346 |
; CHECK: %[[#varPtr:]] = OpVariable %[[#]] Function |
| 347 |
; CHECK: %[[#frac:]] = OpExtInst %[[#var2]] %[[#extinst_id]] modf %[[#d]] %[[#varPtr]] |
| 348 |
; CHECK: %[[#integral:]] = OpLoad %[[#var2]] %[[#varPtr]] |
| 349 |
; CHECK: OpStore %[[#fracPtr]] %[[#frac]] |
| 350 |
; CHECK: OpStore %[[#integralPtr]] %[[#integral]] |
| 351 |
; CHECK: OpFunctionEnd |
| 352 |
define void @TestModf(double %d, ptr addrspace(1) %frac, ptr addrspace(1) %integral) { |
| 353 |
entry: |
| 354 |
%4 = tail call { double, double } @llvm.modf.f64(double %d) |
| 355 |
%5 = extractvalue { double, double } %4, 0 |
| 356 |
%6 = extractvalue { double, double } %4, 1 |
| 357 |
store double %5, ptr addrspace(1) %frac, align 8 |
| 358 |
store double %6, ptr addrspace(1) %integral, align 8 |
| 359 |
ret void |
| 360 |
} |
| 361 |
|
| 362 |
; CHECK: OpFunction |
| 363 |
; CHECK: %[[#d:]] = OpFunctionParameter %[[#]] |
| 364 |
; CHECK: %[[#fracPtr:]] = OpFunctionParameter %[[#]] |
| 365 |
; CHECK: %[[#integralPtr:]] = OpFunctionParameter %[[#]] |
| 366 |
; CHECK: %[[#entryBlock:]] = OpLabel |
| 367 |
; CHECK: %[[#varPtr:]] = OpVariable %[[#]] Function |
| 368 |
; CHECK: OpBranchConditional %[[#]] %[[#lor_lhs_falseBlock:]] %[[#if_thenBlock:]] |
| 369 |
; CHECK: %[[#lor_lhs_falseBlock]] = OpLabel |
| 370 |
; CHECK: OpBranchConditional %[[#]] %[[#if_endBlock:]] %[[#if_thenBlock]] |
| 371 |
; CHECK: %[[#if_thenBlock]] = OpLabel |
| 372 |
; CHECK: OpBranch %[[#returnBlock:]] |
| 373 |
; CHECK: %[[#if_endBlock]] = OpLabel |
| 374 |
; CHECK: %[[#frac:]] = OpExtInst %[[#var2]] %[[#extinst_id]] modf %[[#d]] %[[#varPtr]] |
| 375 |
; CHECK: %[[#integral:]] = OpLoad %[[#var2]] %[[#varPtr]] |
| 376 |
; CHECK: OpStore %[[#fracPtr]] %[[#frac]] |
| 377 |
; CHECK: OpStore %[[#integralPtr]] %[[#integral]] |
| 378 |
; CHECK: OpFunctionEnd |
| 379 |
define dso_local void @TestModf2(double noundef %d, ptr noundef %frac, ptr noundef %integral) { |
| 380 |
entry: |
| 381 |
%0 = load ptr, ptr %frac, align 8 |
| 382 |
%tobool = icmp ne ptr %0, null |
| 383 |
br i1 %tobool, label %lor.lhs.false, label %if.then |
| 384 |
|
| 385 |
lor.lhs.false: |
| 386 |
%1 = load ptr, ptr %integral, align 8 |
| 387 |
%tobool1 = icmp ne ptr %1, null |
| 388 |
br i1 %tobool1, label %if.end, label %if.then |
| 389 |
|
| 390 |
if.then: |
| 391 |
br label %return |
| 392 |
|
| 393 |
if.end: |
| 394 |
%6 = tail call { double, double } @llvm.modf.f64(double %d) |
| 395 |
%7 = extractvalue { double, double } %6, 0 |
| 396 |
%8 = extractvalue { double, double } %6, 1 |
| 397 |
store double %7, ptr %frac, align 4 |
| 398 |
store double %8, ptr %integral, align 4 |
| 399 |
br label %return |
| 400 |
|
| 401 |
return: |
| 402 |
ret void |
| 403 |
} |
| 404 |
|
| 405 |
declare { double, double } @llvm.modf.f64(double) |