[llvm] InstCombine: recognize rotate patterns using ~X (PR #173200)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 22 01:53:34 PST 2025


================
@@ -3020,6 +3020,16 @@ InstCombinerImpl::convertOrOfShiftsToFunnelShift(Instruction &Or) {
       if (match(L, m_ZExt(m_And(m_Value(X), m_SpecificInt(Mask)))) &&
           match(R, m_ZExt(m_And(m_Neg(m_Specific(X)), m_SpecificInt(Mask)))))
         return L;
+      
+            // (~X & (Width - 1)) and (X + 1)
+      if (match(L, m_And(m_Not(m_Value(X)), m_SpecificInt(Mask))) &&
+          match(R, m_Add(m_Specific(X), m_SpecificInt(1))))
+        return X;
+
+      if (match(R, m_And(m_Not(m_Value(X)), m_SpecificInt(Mask))) &&
+          match(L, m_Add(m_Specific(X), m_SpecificInt(1))))
+        return X;
+
----------------
RKSimon wrote:

need clang-format and remove unnecessary newline at the bottom

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


More information about the llvm-commits mailing list