[llvm] [ValueTracking] Add rotate idiom to haveNoCommonBitsSet special cases (PR #122165)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 9 00:40:12 PST 2025


================
@@ -229,6 +229,19 @@ static bool haveNoCommonBitsSetSpecialCases(const Value *LHS, const Value *RHS,
       return true;
   }
 
+  // Look for: (X << V) op (Y >> (BitWidth - V))
+  // or        (X >> V) op (Y << (BitWidth - V))
+  {
+    const Value *V;
+    const APInt *R;
+    if (((match(RHS, m_Shl(m_Value(), m_Sub(m_APInt(R), m_Value(V)))) &&
+          match(LHS, m_LShr(m_Value(), m_Specific(V)))) ||
+         (match(RHS, m_LShr(m_Value(), m_Sub(m_APInt(R), m_Value(V)))) &&
+          match(LHS, m_Shl(m_Value(), m_Specific(V))))) &&
+        R->uge(LHS->getType()->getScalarType()->getIntegerBitWidth()))
----------------
dtcxzyw wrote:

```suggestion
        R->uge(LHS->getType()->getScalarSizeInBits()))
```

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


More information about the llvm-commits mailing list