File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2645,7 +2645,7 @@ class OpenCLStdToSPIRVFriendlyIRMangleInfo : public BuiltinFuncMangleInfo {
26452645public:
26462646 OpenCLStdToSPIRVFriendlyIRMangleInfo(OCLExtOpKind ExtOpId,
26472647 ArrayRef<Type *> ArgTys, Type *RetTy)
2648- : ExtOpId(ExtOpId), ArgTys(ArgTys) {
2648+ : ExtOpId(ExtOpId), ArgTys(ArgTys), RetTy(RetTy) {
26492649
26502650 std::string Postfix = "";
26512651 if (needRetTypePostfix())
@@ -2661,6 +2661,11 @@ class OpenCLStdToSPIRVFriendlyIRMangleInfo : public BuiltinFuncMangleInfo {
26612661 case OpenCLLIB::Vloada_halfn:
26622662 case OpenCLLIB::Vloadn:
26632663 return true;
2664+ case OpenCLLIB::Nan:
2665+ // Only add return type mangling for bfloat16 to disambiguate from half
2666+ // (both are represented as i16 in LLVM). Float and half use traditional
2667+ // naming for backward compatibility.
2668+ return RetTy->getScalarType()->isBFloatTy();
26642669 default:
26652670 return false;
26662671 }
@@ -2722,6 +2727,7 @@ class OpenCLStdToSPIRVFriendlyIRMangleInfo : public BuiltinFuncMangleInfo {
27222727private:
27232728 OCLExtOpKind ExtOpId;
27242729 ArrayRef<Type *> ArgTys;
2730+ Type *RetTy;
27252731};
27262732} // namespace
27272733
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