[llvm] [ValueTracking] Recognize `LShr(UINT_MAX, Y) + 1` as a power-of-two (PR #91171)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon May 6 03:16:13 PDT 2024


================
@@ -2173,6 +2174,13 @@ bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero, unsigned Depth,
         if (OrZero || RHSBits.One.getBoolValue() || LHSBits.One.getBoolValue())
           return true;
     }
+
+    // LShr(UINT_MAX, Y) + 1 is a power of two (if nuw) or zero.
+    if (OrZero || Q.IIQ.hasNoUnsignedWrap(VOBO)) {
+      APInt UIntMax = APInt::getMaxValue(BitWidth);
+      if (match(I, m_Add(m_LShr(m_SpecificInt(UIntMax), m_Value()), m_One())))
----------------
nikic wrote:

```suggestion
      if (match(I, m_Add(m_LShr(m_AllOnes(), m_Value()), m_One())))
```

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


More information about the llvm-commits mailing list