[llvm] [InstCombine] Recognize abs through positive-K nsw multiply. (PR #207539)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 7 00:32:40 PDT 2026


================
@@ -9078,12 +9078,16 @@ static SelectPatternResult matchSelectPattern(CmpInst::Predicate Pred,
 
   if (isKnownNegation(TrueVal, FalseVal)) {
     // Sign-extending LHS does not change its sign, so TrueVal/FalseVal can
-    // match against either LHS or sext(LHS).
-    auto MaybeSExtCmpLHS =
+    // match against either LHS or sign-preserving operations on LHS, like
+    // sext(LHS), or binary ops that do not wrap in signed sense.
+    auto CmpLHSOrSExt =
         m_CombineOr(m_Specific(CmpLHS), m_SExt(m_Specific(CmpLHS)));
+    auto MaybeSExtOrMulCmpLHS = m_CombineOr(
+        CmpLHSOrSExt, m_CombineOr(m_NSWMul(CmpLHSOrSExt, m_StrictlyPositive()),
+                                  m_NSWShl(CmpLHSOrSExt, m_Value())));
----------------
nikic wrote:

I believe m_CombineOr is variadic nowadays, so you could make all of these part of one m_CombineOr instead of nesting them.

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


More information about the llvm-commits mailing list