From 093cf279cad6f12bb22abf0a94eae9aca938aaea Mon Sep 17 00:00:00 2001 From: Sven van Haastregt Date: Thu, 25 Apr 2024 10:38:12 +0200 Subject: [PATCH] [Backport to 13] Skip adding decorations for OpForward (#2529) (#2542) When a temporary `OpForward` instruction is needed during translation to SPIR-V, do not add the decorations yet, as that would result in duplicate decorations when the actual instruction is visited and the `OpForward` is replaced by a real SPIR-V instruction. The SPIR-V Validator has recently started checking for duplicate decorations; this fixes some but not all issues arising from the new checks. Contributes to https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/2509 (cherry picked from commit a2783135be3f37f1e210aaf219b45a3226d32813) --- lib/SPIRV/SPIRVWriter.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/SPIRV/SPIRVWriter.cpp b/lib/SPIRV/SPIRVWriter.cpp index 61c9545d93..d083f1d2d2 100644 --- a/lib/SPIRV/SPIRVWriter.cpp +++ b/lib/SPIRV/SPIRVWriter.cpp @@ -1025,8 +1025,13 @@ SPIRVValue *LLVMToSPIRVBase::transValue(Value *V, SPIRVBasicBlock *BB, isa(V) || BB) && "Invalid SPIRV BB"); - auto BV = transValueWithoutDecoration(V, BB, CreateForward, FuncTrans); - if (!BV || !transDecoration(V, BV)) + auto *BV = transValueWithoutDecoration(V, BB, CreateForward, FuncTrans); + if (!BV) + return nullptr; + // Only translate decorations for non-forward instructions. Forward + // instructions will have their decorations translated when the actual + // instruction is seen and rewritten to a real SPIR-V instruction. + if (!BV->isForward() && !transDecoration(V, BV)) return nullptr; StringRef Name = V->getName(); if (!Name.empty()) // Don't erase the name, which BM might already have