[llvm] [SPIR-V] Fix OpDecorate insertion point for non-PHI defs in decorateUsesAsNonUniform (PR #212524)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 28 08:52:09 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-spir-v
Author: Arseniy Obolenskiy (aobolensk)
<details>
<summary>Changes</summary>
Inserting before the defining instruction placed the decoration ahead of its own operand, breaking dominance for the loop-carried case
Fix machine code errors from https://github.com/llvm/llvm-project/pull/208224#issuecomment-5095074660
---
Full diff: https://github.com/llvm/llvm-project/pull/212524.diff
2 Files Affected:
- (modified) llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp (+2-1)
- (modified) llvm/test/CodeGen/SPIRV/hlsl-resources/NonUniformIdx/RWBufferNonUniformIdxLoop.ll (+1-1)
``````````diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index c8f705e0251b6..a45a978b5d11e 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -6452,7 +6452,8 @@ void SPIRVInstructionSelector::decorateUsesAsNonUniform(
if (!IsDecorated) {
MachineBasicBlock &MBB = *DefMI->getParent();
- MachineInstr &InsertPt = DefMI->isPHI() ? *MBB.getFirstNonPHI() : *DefMI;
+ MachineInstr &InsertPt =
+ DefMI->isPHI() ? *MBB.getFirstNonPHI() : *DefMI->getNextNode();
buildOpDecorate(CurrentReg, InsertPt, TII,
SPIRV::Decoration::NonUniformEXT, {});
}
diff --git a/llvm/test/CodeGen/SPIRV/hlsl-resources/NonUniformIdx/RWBufferNonUniformIdxLoop.ll b/llvm/test/CodeGen/SPIRV/hlsl-resources/NonUniformIdx/RWBufferNonUniformIdxLoop.ll
index e9dda9e94515c..ca892fefd3af4 100644
--- a/llvm/test/CodeGen/SPIRV/hlsl-resources/NonUniformIdx/RWBufferNonUniformIdxLoop.ll
+++ b/llvm/test/CodeGen/SPIRV/hlsl-resources/NonUniformIdx/RWBufferNonUniformIdxLoop.ll
@@ -1,4 +1,4 @@
-; RUN: llc -O0 -mtriple=spirv1.6-unknown-vulkan1.3-compute %s -o - | FileCheck %s
+; RUN: llc -O0 -mtriple=spirv1.6-unknown-vulkan1.3-compute -verify-machineinstrs %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv1.6-unknown-vulkan1.3-compute %s -o - -filetype=obj | spirv-val %}
; A non-uniform index carried across a loop through a phi creates an SSA cycle
``````````
</details>
https://github.com/llvm/llvm-project/pull/212524
More information about the llvm-commits
mailing list