[llvm] ac7e309 - [SPIR-V] Erase all instructions after OpKill, not just the next one (#219022)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 28 01:47:17 PDT 2026
Author: Arseniy Obolenskiy
Date: 2026-08-28T10:47:12+02:00
New Revision: ac7e309f3395d101de9ca75ab70ddeccdb91d4ad
URL: https://github.com/llvm/llvm-project/commit/ac7e309f3395d101de9ca75ab70ddeccdb91d4ad
DIFF: https://github.com/llvm/llvm-project/commit/ac7e309f3395d101de9ca75ab70ddeccdb91d4ad.diff
LOG: [SPIR-V] Erase all instructions after OpKill, not just the next one (#219022)
Added:
Modified:
llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/discard.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index 2ec4ede8dd8f5..891a8d9da12cf 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -22,6 +22,7 @@
#include "SPIRVTypeInst.h"
#include "SPIRVUtils.h"
#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/STLFunctionalExtras.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringExtras.h"
@@ -4500,6 +4501,7 @@ bool SPIRVInstructionSelector::selectDiscard(Register ResVReg,
MachineInstr &I) const {
unsigned Opcode;
+ MachineBasicBlock &BB = *I.getParent();
if (STI.canUseExtension(
SPIRV::Extension::SPV_EXT_demote_to_helper_invocation) ||
@@ -4508,13 +4510,13 @@ bool SPIRVInstructionSelector::selectDiscard(Register ResVReg,
} else {
Opcode = SPIRV::OpKill;
// OpKill must be the last operation of any basic block.
- if (MachineInstr *NextI = I.getNextNode()) {
- GR.invalidateMachineInstr(NextI);
- NextI->eraseFromParent();
+ for (MachineInstr &ToErase : make_early_inc_range(
+ make_range(std::next(I.getIterator()), BB.instr_end()))) {
+ GR.invalidateMachineInstr(&ToErase);
+ ToErase.eraseFromParent();
}
}
- MachineBasicBlock &BB = *I.getParent();
BuildMI(BB, I, I.getDebugLoc(), TII.get(Opcode))
.constrainAllUses(TII, TRI, RBI);
return true;
diff --git a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/discard.ll b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/discard.ll
index 39be59bbc7332..fb13464010115 100644
--- a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/discard.ll
+++ b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/discard.ll
@@ -47,6 +47,32 @@ end: ; preds = %lt0, %entry
}
declare void @llvm.spv.discard()
+define void @test_scalar_multi_instr_after_discard(float noundef %Buf, ptr %Out) {
+entry:
+; CHECK-LABEL: ; -- Begin function test_scalar_multi_instr_after_discard
+; CHECK: OpBranchConditional %[[#]] %[[#truel:]] %[[#endl:]]
+; CHECK: %[[#truel]] = OpLabel
+; SPIRV15: OpKill
+; SPIRV15-NOT: OpStore
+; SPIRV16: OpDemoteToHelperInvocation
+; SPIRV16: OpBranch %[[#endl]]
+; CHECK: %[[#endl]] = OpLabel
+ %Buf.addr = alloca float, align 4
+ store float %Buf, ptr %Buf.addr, align 4
+ %1 = load float, ptr %Buf.addr, align 4
+ %2 = fcmp olt float %1, 0.000000e+00
+ br i1 %2, label %lt0, label %end
+
+lt0: ; preds = %entry
+ call void @llvm.spv.discard()
+ store volatile float 1.0, ptr %Out, align 4
+ store volatile float 2.0, ptr %Out, align 4
+ br label %end
+
+end: ; preds = %lt0, %entry
+ ret void
+}
+
define void @test_vector(<4 x float> noundef %Buf) {
entry:
; CHECK-LABEL: ; -- Begin function test_vector
More information about the llvm-commits
mailing list