[llvm] [AArch64] Report icmp as free if it can be folded into ands (PR #143286)

Sam Tebbs via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 16 03:37:20 PDT 2025


================
@@ -4346,14 +4346,23 @@ InstructionCost AArch64TTIImpl::getCmpSelInstrCost(
   }
 
   // Treat the icmp in icmp(and, 0) as free, as we can make use of ands.
-  // FIXME: This can apply to more conditions and add/sub if it can be shown to
-  // be profitable.
   if (ValTy->isIntegerTy() && ISD == ISD::SETCC && I &&
-      ICmpInst::isEquality(VecPred) &&
+      !CmpInst::isUnsigned(VecPred) &&
       TLI->isTypeLegal(TLI->getValueType(DL, ValTy)) &&
-      match(I->getOperand(1), m_Zero()) &&
-      match(I->getOperand(0), m_And(m_Value(), m_Value())))
-    return 0;
+      match(I->getOperand(0), m_And(m_Value(), m_Value()))) {
+    if (match(I->getOperand(1), m_Zero()))
+      return 0;
+
+    // x >= 1 / x < 1 -> x > 0 / x <= 0
----------------
SamTebbs33 wrote:

I think you could explain that these patterns get folded into an `ands`, to show why their cost is zero.

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


More information about the llvm-commits mailing list