[llvm] [InstCombine] Add combines for unsigned comparison of absolute value to constant (PR #172021)

Nathan Corbyn via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 5 04:21:13 PST 2026


================
@@ -7602,6 +7602,51 @@ Instruction *InstCombinerImpl::foldICmpCommutative(CmpPredicate Pred,
     }
   }
 
+  // abs(X) u> K --> K >= 0 ? `X + K u> 2 * K`              : `false`
+  // If abs(INT_MIN) is poison:
+  // abs(X) u< K --> K >= 1 ? `X + (K - 1) u<= 2 * (K - 1)` : K != 0
+  {
+    Value *X;
+    ConstantInt *C, *K;
+    bool Frozen = false;
+    if ((match(Op0,
+               m_Intrinsic<Intrinsic::abs>(m_Value(X), m_ConstantInt(C))) ||
+         (Frozen = match(Op0, m_Freeze(m_Intrinsic<Intrinsic::abs>(
+                                  m_Value(X), m_ConstantInt(C)))))) &&
+        match(Op1, m_ConstantInt(K))) {
----------------
cofibrant wrote:

Thanks, will do!

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


More information about the llvm-commits mailing list