[llvm] 594cce3 - [AMDGPU] Change static NOP last terminator SI_DEMOTE_I1 to be replaced by S_BRANCH instead of assert (#204649)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 23 12:48:11 PDT 2026


Author: Domenic Nutile
Date: 2026-06-23T15:48:06-04:00
New Revision: 594cce3cbcdbe46d6f9ac3c6a53f86ae63c5bc42

URL: https://github.com/llvm/llvm-project/commit/594cce3cbcdbe46d6f9ac3c6a53f86ae63c5bc42
DIFF: https://github.com/llvm/llvm-project/commit/594cce3cbcdbe46d6f9ac3c6a53f86ae63c5bc42.diff

LOG: [AMDGPU] Change static NOP last terminator SI_DEMOTE_I1 to be replaced by S_BRANCH instead of assert (#204649)

This issue was first discovered in some testing downstream. A specific
chain of transformations on a ballot instruction with a constant
argument followed by an llvm.amgcn.wqm.demote call leads to an
instruction of `SI_DEMOTE_I1 -1, 0` being the last terminator of a block
with a single successor. This instruction is a NOP and can safely be
replaced with an S_BRANCH to the block's successor instead of asserting
failure.

The test added in this change is a very simplified recreation of the
pattern seen in the shader compilation in the downstream that lead to
assertion failure

Added: 
    llvm/test/CodeGen/AMDGPU/uniform-intrin-combine-wqm-demote.ll

Modified: 
    llvm/lib/Target/AMDGPU/SIWholeQuadMode.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/SIWholeQuadMode.cpp b/llvm/lib/Target/AMDGPU/SIWholeQuadMode.cpp
index bf5dc2c529be6..008f7f70456df 100644
--- a/llvm/lib/Target/AMDGPU/SIWholeQuadMode.cpp
+++ b/llvm/lib/Target/AMDGPU/SIWholeQuadMode.cpp
@@ -979,7 +979,7 @@ MachineInstr *SIWholeQuadMode::lowerKillI1(MachineInstr &MI, bool IsWQM) {
       if (!IsLastTerminator) {
         LIS->RemoveMachineInstrFromMaps(MI);
       } else {
-        assert(MBB.succ_size() == 1 && MI.getOpcode() != AMDGPU::SI_DEMOTE_I1);
+        assert(MBB.succ_size() == 1);
         MachineInstr *NewTerm = BuildMI(MBB, MI, DL, TII->get(AMDGPU::S_BRANCH))
                                     .addMBB(*MBB.succ_begin());
         LIS->ReplaceMachineInstrInMaps(MI, *NewTerm);

diff  --git a/llvm/test/CodeGen/AMDGPU/uniform-intrin-combine-wqm-demote.ll b/llvm/test/CodeGen/AMDGPU/uniform-intrin-combine-wqm-demote.ll
new file mode 100644
index 0000000000000..6e82e70b56c57
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/uniform-intrin-combine-wqm-demote.ll
@@ -0,0 +1,17 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -mtriple=amdgcn--amdpal -mcpu=gfx1100 < %s | FileCheck %s
+
+define amdgpu_ps void @_amdgpu_ps_main() "amdgpu-conditional-discard-transformations" "amdgpu-transform-discard-to-demote" {
+; CHECK-LABEL: _amdgpu_ps_main:
+; CHECK:       ; %bb.0: ; %.entry
+; CHECK-NEXT:    s_endpgm
+.entry:
+  %ballot = call i64 @llvm.amdgcn.ballot.i64(i1 true)
+  %not_ballot = icmp eq i64 %ballot, 0
+  %inverse = xor i1 %not_ballot, true
+  call void @llvm.amdgcn.wqm.demote(i1 %inverse)
+  br label %.exit
+
+.exit:
+  ret void
+}


        


More information about the llvm-commits mailing list