[llvm] [AMDGPU] Use s_cmovk_i32 instead of s_cselect_b32 when applicable (PR #135232)

Ryan Buchner via llvm-commits llvm-commits at lists.llvm.org
Fri May 2 11:12:44 PDT 2025


================
@@ -883,6 +883,50 @@ bool SIShrinkInstructions::run(MachineFunction &MF) {
         }
       }
 
+      // Try to use S_CMOVK_I32 in place of S_CSELECT_B32
+      if (MI.getOpcode() == AMDGPU::S_CSELECT_B32) {
+        const MachineOperand *Dest = &MI.getOperand(0);
+        MachineOperand *Src0 = &MI.getOperand(1);
+        MachineOperand *Src1 = &MI.getOperand(2);
+        // Must be exactly one Immediate
+        if (!(Src0->isReg() ^ Src1->isReg()))
----------------
bababuck wrote:

I didn't consider that. We would also have to commute any other instructions dependent on the compare.

I removed the commute logic for now, I can open a separate MR later to address the commutability. There is one test case in the `lit` tests that no longer is optimized after removing the commute from this MR.

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


More information about the llvm-commits mailing list