Skip to content

Commit ac3c032

Browse files
wenju-hevmaksimo
authored andcommitted
[Backport to 20] Partial pick of #3106 - Set an arg of __spirv_ocl_nan to unsigned
OpenCL built-in nan's argument type is unsigned.
1 parent 0a2df5a commit ac3c032

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/SPIRV/SPIRVUtil.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,6 +2650,9 @@ class OpenCLStdToSPIRVFriendlyIRMangleInfo : public BuiltinFuncMangleInfo {
26502650
case OpenCLLIB::S_Upsample:
26512651
addUnsignedArg(1);
26522652
break;
2653+
case OpenCLLIB::Nan:
2654+
addUnsignedArg(0);
2655+
break;
26532656
case OpenCLLIB::Vloadn:
26542657
case OpenCLLIB::Vload_half:
26552658
case OpenCLLIB::Vload_halfn:

test/transcoding/OpenCL/nan.ll

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: llvm-spirv %t.spv -to-text -o %t.spt
4+
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
5+
6+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
7+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefixes=CHECK-LLVM
8+
; RUN: llvm-spirv -r %t.spv --spirv-target-env=SPV-IR -o %t.rev.bc
9+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefixes=CHECK-SPV-IR
10+
11+
; Check OpenCL built-in nan translation.
12+
13+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G1"
14+
target triple = "spir64"
15+
16+
; CHECK-SPIRV: ExtInst [[#]] [[#]] [[#]] nan
17+
18+
; CHECK-LLVM: call spir_func float @_Z3nanj(
19+
20+
; CHECK-SPV-IR: call spir_func float @_Z15__spirv_ocl_nanj(
21+
22+
define dso_local spir_kernel void @test(ptr addrspace(1) align 4 %a, i32 %b) {
23+
entry:
24+
%call = tail call spir_func float @_Z3nanj(i32 %b)
25+
store float %call, ptr addrspace(1) %a, align 4
26+
ret void
27+
}
28+
29+
declare spir_func float @_Z3nanj(i32)
30+
31+
!opencl.ocl.version = !{!0}
32+
33+
!0 = !{i32 3, i32 0}

0 commit comments

Comments
 (0)