File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed
Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -2601,7 +2601,7 @@ class OpenCLStdToSPIRVFriendlyIRMangleInfo : public BuiltinFuncMangleInfo {
26012601public:
26022602 OpenCLStdToSPIRVFriendlyIRMangleInfo (OCLExtOpKind ExtOpId,
26032603 ArrayRef<Type *> ArgTys, Type *RetTy)
2604- : ExtOpId(ExtOpId), ArgTys(ArgTys) {
2604+ : ExtOpId(ExtOpId), ArgTys(ArgTys), RetTy(RetTy) {
26052605
26062606 std::string Postfix = " " ;
26072607 if (needRetTypePostfix ())
@@ -2617,6 +2617,11 @@ class OpenCLStdToSPIRVFriendlyIRMangleInfo : public BuiltinFuncMangleInfo {
26172617 case OpenCLLIB::Vloada_halfn:
26182618 case OpenCLLIB::Vloadn:
26192619 return true ;
2620+ case OpenCLLIB::Nan:
2621+ // Only add return type mangling for bfloat16 to disambiguate from half
2622+ // (both are represented as i16 in LLVM). Float and half use traditional
2623+ // naming for backward compatibility.
2624+ return RetTy->getScalarType ()->isBFloatTy ();
26202625 default :
26212626 return false ;
26222627 }
@@ -2669,6 +2674,7 @@ class OpenCLStdToSPIRVFriendlyIRMangleInfo : public BuiltinFuncMangleInfo {
26692674private:
26702675 OCLExtOpKind ExtOpId;
26712676 ArrayRef<Type *> ArgTys;
2677+ Type *RetTy;
26722678};
26732679} // namespace
26742680
Original file line number Diff line number Diff line change 1+ ; RUN: llvm-as %s -o %t.bc
2+ ; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_KHR_bfloat16 -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 --spirv-target-env=SPV-IR -o - | llvm-dis -o %t.rev.ll
7+ ; RUN: FileCheck < %t.rev.ll %s --check-prefixes=CHECK-SPV-IR
8+
9+ ; Check OpenCL built-in nan translation.
10+ ; Verify it's possible to distinguish between bfloat and half versions.
11+
12+ 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"
13+ target triple = "spir64"
14+
15+ ; CHECK-SPIRV: TypeFloat [[#BFLOAT:]] 16 0 {{$}}
16+ ; CHECK-SPIRV: TypeFloat [[#HALF:]] 16 {{$}}
17+ ; CHECK-SPIRV: ExtInst [[#BFLOAT]] [[#]] [[#]] nan
18+ ; CHECK-SPIRV: ExtInst [[#HALF]] [[#]] [[#]] nan
19+
20+ ; CHECK-SPV-IR: call spir_func bfloat @_Z22__spirv_ocl_nan_RDF16bt(
21+ ; CHECK-SPV-IR: call spir_func half @_Z15__spirv_ocl_nant(
22+
23+ define dso_local spir_kernel void @test_bfloat (ptr addrspace (1 ) align 2 %a , i16 %b ) {
24+ entry:
25+ %call = tail call spir_func bfloat @_Z23__spirv_ocl_nan__RDF16bt (i16 %b )
26+ %call2 = tail call spir_func half @_Z22__spirv_ocl_nan__Rhalft (i16 %b )
27+ ret void
28+ }
29+
30+ declare spir_func bfloat @_Z23__spirv_ocl_nan__RDF16bt (i16 )
31+ declare spir_func half @_Z22__spirv_ocl_nan__Rhalft (i16 )
32+
33+
34+ !opencl.ocl.version = !{!0 }
35+
36+ !0 = !{i32 3 , i32 0 }
You can’t perform that action at this time.
0 commit comments