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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri May 2 07:59:22 PDT 2025


================
@@ -883,6 +883,50 @@ bool SIShrinkInstructions::run(MachineFunction &MF) {
         }
       }
 
+      // Try to use S_MOVK_I32
+      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()))
+          continue;
+
+        bool swapped = false;
+        // Don't actually swap the MachineOperands yet
+        // Could do it now, but don't want to since will modify generated
+        // program even in cases where we don't insert a S_CMOVK_I32
+        if (!Src0->isReg() && Src1->isReg()) {
+          swapped = true;
+          std::swap(Src0, Src1);
+        }
+
+        if (!(Src1->isImm() && isKImmOperand(*Src1)))
----------------
arsenm wrote:

You wrote this as !(X && Y) instead of !X || !Y

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


More information about the llvm-commits mailing list