[llvm] [SPIR-V] Reject fp128 and ppc_fp128 types with a diagnostic (PR #208397)
Arseniy Obolenskiy via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 9 02:28:46 PDT 2026
https://github.com/aobolensk updated https://github.com/llvm/llvm-project/pull/208397
>From 51f21c45bf6922574040773bc56ea6b1c47d967e Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Thu, 9 Jul 2026 10:47:58 +0200
Subject: [PATCH 1/2] [SPIR-V] Reject fp128 and ppc_fp128 types with a
diagnostic
---
llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp | 6 ++++++
llvm/test/CodeGen/SPIRV/constant/fp128-unsupported.ll | 10 ++++++++++
2 files changed, 16 insertions(+)
create mode 100644 llvm/test/CodeGen/SPIRV/constant/fp128-unsupported.ll
diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
index eea63194fa8b7..4ea4067d69bb4 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
@@ -1204,6 +1204,12 @@ SPIRVTypeInst SPIRVGlobalRegistry::createSPIRVType(
: getOpTypeInt(Width, MIRBuilder, false);
}
if (Ty->isFloatingPointTy()) {
+ if (Ty->isFP128Ty() || Ty->isPPC_FP128Ty()) {
+ Function &F = MIRBuilder.getMF().getFunction();
+ F.getContext().diagnose(DiagnosticInfoUnsupported(
+ F, "fp128 is not supported in SPIR-V", DebugLoc(), DS_Error));
+ return getOpTypeFloat(64, MIRBuilder);
+ }
if (Ty->isBFloatTy()) {
return getOpTypeFloat(Ty->getPrimitiveSizeInBits(), MIRBuilder,
SPIRV::FPEncoding::BFloat16KHR);
diff --git a/llvm/test/CodeGen/SPIRV/constant/fp128-unsupported.ll b/llvm/test/CodeGen/SPIRV/constant/fp128-unsupported.ll
new file mode 100644
index 0000000000000..d10c99c12cfe7
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/constant/fp128-unsupported.ll
@@ -0,0 +1,10 @@
+; Test that fp128 and ppc_fp128, which are not valid standard SPIR-V types,
+; produce an error instead of being silently miscompiled.
+
+; RUN: not llc -O0 -mtriple=spirv32-unknown-unknown %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: error:{{.*}}fp128 is not supported in SPIR-V
+
+define fp128 @getConstantFP128() {
+ ret fp128 0xL00000000000000004001000000000000
+}
>From 140cab4e2c26e40e9ed10f9950ac0a667e11a977 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Thu, 9 Jul 2026 11:28:35 +0200
Subject: [PATCH 2/2] fix
---
llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
index 4ea4067d69bb4..4233db46e8ef2 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
@@ -395,9 +395,10 @@ Register SPIRVGlobalRegistry::createConstFP(const ConstantFP *CF,
MIB = MIRBuilder.buildInstr(SPIRV::OpConstantF)
.addDef(Res)
.addUse(getSPIRVTypeID(SpvType));
- addNumImm(APInt(BitWidth,
- CF->getValueAPF().bitcastToAPInt().getZExtValue()),
- MIB);
+ APInt RawBits = CF->getValueAPF().bitcastToAPInt();
+ uint64_t ImmBits =
+ RawBits.getBitWidth() <= 64 ? RawBits.getZExtValue() : 0;
+ addNumImm(APInt(BitWidth, ImmBits), MIB);
}
const auto &ST = CurMF->getSubtarget();
constrainSelectedInstRegOperands(*MIB, *ST.getInstrInfo(),
More information about the llvm-commits
mailing list