[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
Mon Jul 13 05:28:16 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/3] [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/3] 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(),

>From 4faa5822f1bc8b2c4f36410886df62dc24377eb7 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Mon, 13 Jul 2026 14:28:04 +0200
Subject: [PATCH 3/3] fatal error

---
 llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp     | 15 +++++----------
 .../CodeGen/SPIRV/constant/fp128-unsupported.ll   |  2 +-
 2 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
index 4233db46e8ef2..6640c8af8d830 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp
@@ -395,10 +395,9 @@ Register SPIRVGlobalRegistry::createConstFP(const ConstantFP *CF,
           MIB = MIRBuilder.buildInstr(SPIRV::OpConstantF)
                     .addDef(Res)
                     .addUse(getSPIRVTypeID(SpvType));
-          APInt RawBits = CF->getValueAPF().bitcastToAPInt();
-          uint64_t ImmBits =
-              RawBits.getBitWidth() <= 64 ? RawBits.getZExtValue() : 0;
-          addNumImm(APInt(BitWidth, ImmBits), MIB);
+          addNumImm(APInt(BitWidth,
+                          CF->getValueAPF().bitcastToAPInt().getZExtValue()),
+                    MIB);
         }
         const auto &ST = CurMF->getSubtarget();
         constrainSelectedInstRegOperands(*MIB, *ST.getInstrInfo(),
@@ -1205,12 +1204,8 @@ 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->isFP128Ty() || Ty->isPPC_FP128Ty())
+      llvm::reportFatalUsageError("fp128 is not supported in SPIR-V");
     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
index d10c99c12cfe7..081356ae9c1d1 100644
--- a/llvm/test/CodeGen/SPIRV/constant/fp128-unsupported.ll
+++ b/llvm/test/CodeGen/SPIRV/constant/fp128-unsupported.ll
@@ -3,7 +3,7 @@
 
 ; 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
+; CHECK: LLVM ERROR: fp128 is not supported in SPIR-V
 
 define fp128 @getConstantFP128() {
   ret fp128 0xL00000000000000004001000000000000



More information about the llvm-commits mailing list