Skip to content

Commit 871e22f

Browse files
wenju-hesys-ce-bb
authored andcommitted
Set an arg of __spirv_ocl_nan/shuffle/shuffle2 to unsigned (#3106)
OpenCL built-in nan's argument type and shuffle/shuffle2's mask argument type is unsigned. DPC++ header also sets unsigned type for them. So this PR changes them to unsigned in SPV-IR. Original commit: KhronosGroup/SPIRV-LLVM-Translator@e8679909a40d7d6
1 parent 87590ce commit 871e22f

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

llvm-spirv/lib/SPIRV/SPIRVUtil.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,6 +2616,15 @@ class OpenCLStdToSPIRVFriendlyIRMangleInfo : public BuiltinFuncMangleInfo {
26162616
case OpenCLLIB::S_Upsample:
26172617
addUnsignedArg(1);
26182618
break;
2619+
case OpenCLLIB::Nan:
2620+
addUnsignedArg(0);
2621+
break;
2622+
case OpenCLLIB::Shuffle:
2623+
addUnsignedArg(1);
2624+
break;
2625+
case OpenCLLIB::Shuffle2:
2626+
addUnsignedArg(2);
2627+
break;
26192628
default:;
26202629
// No special handling is needed
26212630
}
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}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 shuffle and shuffle2 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 [[#]] [[#]] [[#]] shuffle
17+
; CHECK-SPIRV: ExtInst [[#]] [[#]] [[#]] shuffle2
18+
19+
; CHECK-LLVM: call spir_func <2 x float> @_Z7shuffleDv2_fDv2_j(
20+
; CHECK-LLVM: call spir_func <4 x float> @_Z8shuffle2Dv2_fS_Dv4_j(
21+
22+
; CHECK-SPV-IR: call spir_func <2 x float> @_Z19__spirv_ocl_shuffleDv2_fDv2_j(
23+
; CHECK-SPV-IR: call spir_func <4 x float> @_Z20__spirv_ocl_shuffle2Dv2_fS_Dv4_j(
24+
25+
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"
26+
target triple = "spir64"
27+
28+
define spir_kernel void @test() {
29+
entry:
30+
%call = call spir_func <2 x float> @_Z7shuffleDv2_fDv2_j(<2 x float> zeroinitializer, <2 x i32> zeroinitializer)
31+
ret void
32+
}
33+
34+
declare spir_func <2 x float> @_Z7shuffleDv2_fDv2_j(<2 x float>, <2 x i32>)
35+
36+
define spir_kernel void @test2() {
37+
entry:
38+
%call = call spir_func <4 x float> @_Z8shuffle2Dv2_fS_Dv4_j(<2 x float> zeroinitializer, <2 x float> zeroinitializer, <4 x i32> zeroinitializer)
39+
ret void
40+
}
41+
42+
declare spir_func <4 x float> @_Z8shuffle2Dv2_fS_Dv4_j(<2 x float>, <2 x float>, <4 x i32>)
43+
44+
!opencl.ocl.version = !{!0}
45+
46+
!0 = !{i32 3, i32 0}

0 commit comments

Comments
 (0)