[Mlir-commits] [mlir] [mlir][spirv] Fix deserialization issue caused by conflicting OpName instructions (PR #191223)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Apr 9 08:52:04 PDT 2026


https://github.com/jack-slingsby created https://github.com/llvm/llvm-project/pull/191223

The SPIR-V specification allows multiple conflicting OpName instructions to redefine the name associated with a given <id>. Update the deserializer to handle this case by using the last declared name.

>From d46ec477fb12e192e3c1ffee21bba42c43993a40 Mon Sep 17 00:00:00 2001
From: Jack Slingsby <Jack.Slingsby at imgtec.com>
Date: Thu, 9 Apr 2026 14:58:50 +0100
Subject: [PATCH] Fix issue deserailizing SPIRV OpName

---
 .../lib/Target/SPIRV/Deserialization/Deserializer.cpp | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
index 933433bcaa57a..a798114e4e556 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
@@ -1019,17 +1019,18 @@ LogicalResult spirv::Deserializer::processName(ArrayRef<uint32_t> operands) {
   if (operands.size() < 2) {
     return emitError(unknownLoc, "OpName needs at least 2 operands");
   }
-  if (!nameMap.lookup(operands[0]).empty()) {
-    return emitError(unknownLoc, "duplicate name found for result <id> ")
-           << operands[0];
-  }
+
   unsigned wordIndex = 1;
   StringRef name = decodeStringLiteral(operands, wordIndex);
   if (wordIndex != operands.size()) {
     return emitError(unknownLoc,
                      "unexpected trailing words in OpName instruction");
   }
-  nameMap[operands[0]] = name;
+
+  // In SPIRV it's valid for multiple OpName instructions to refer to the same
+  // <id>. Use a "last one wins" approach to resolve such cases.
+  nameMap.emplace_or_assign(operands[0], name);
+
   return success();
 }
 



More information about the Mlir-commits mailing list