[llvm] [AMDGPU] Fold compares of S_CSELECT of two different constants (PR #227772)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 14:47:36 PDT 2026


================
@@ -11671,6 +11671,29 @@ static bool foldableSelect(const MachineInstr &Def) {
   return Op1IsNonZeroImm && Op2IsZeroImm;
 }
 
+/// If \p Sel is an S_CSELECT* of two different constants A and B, return them,
+/// truncated to the width of the select.
+static std::optional<std::pair<int64_t, int64_t>>
+getSelectConstants(const SIInstrInfo &TII, const MachineRegisterInfo &MRI,
+                   const MachineInstr &Sel) {
+  unsigned Opc = Sel.getOpcode();
+  if (Opc != AMDGPU::S_CSELECT_B32 && Opc != AMDGPU::S_CSELECT_B64)
+    return {};
+  std::optional<int64_t> A =
+      TII.getImmOrMaterializedImm(MRI, Sel.getOperand(1));
+  std::optional<int64_t> B =
----------------
arsenm wrote:

Early exit after the first use?

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


More information about the llvm-commits mailing list