[llvm] [SPIR-V] Fix OpDecorate insertion point for non-PHI defs in decorateUsesAsNonUniform (PR #212524)
Arseniy Obolenskiy via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 28 08:51:24 PDT 2026
https://github.com/aobolensk created https://github.com/llvm/llvm-project/pull/212524
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
>From b9f8e08d15e4543412db097546a5901ff0cce066 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Tue, 28 Jul 2026 17:49:05 +0200
Subject: [PATCH] [SPIR-V] Fix OpDecorate insertion point for non-PHI defs in
decorateUsesAsNonUniform
Inserting before the defining instruction placed the decoration ahead of its own operand, breaking dominance for the loop-carried case
---
llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp | 3 ++-
.../hlsl-resources/NonUniformIdx/RWBufferNonUniformIdxLoop.ll | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
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
More information about the llvm-commits
mailing list