[llvm] [SPIR-V] Erase all instructions after OpKill, not just the next one (PR #219022)

Juan Manuel Martinez CaamaƱo via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 28 01:34:21 PDT 2026


================
@@ -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
----------------
jmmartinez wrote:

What I meant is that when we delete instructions moving forward in a block, we delete the instructions that generate a value before their users.

But I'm almost sure that it doesn't matter in the IR at this point (It'd be different on llvm-ir).

https://github.com/llvm/llvm-project/pull/219022


More information about the llvm-commits mailing list