[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:36 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-spirv

Author: Jack (jack-slingsby)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/191223.diff


1 Files Affected:

- (modified) mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp (+6-5) 


``````````diff
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();
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/191223


More information about the Mlir-commits mailing list