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