[PATCH] D142271: [ValueTracking] Add KnownBits patterns `xor(x, x - 1)` and `and(x, -x)` for knowing upper bits to be zero

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 14:11:38 PST 2023


goldstein.w.n marked 2 inline comments as not done.
goldstein.w.n added inline comments.


================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:1094
+          match(I->getOperand(1), m_Neg(m_Specific(I->getOperand(0))))) {
+        unsigned MinBit = std::min(Known.One.countTrailingZeros(),
+                                   Known2.One.countTrailingZeros());
----------------
craig.topper wrote:
> I'm not sure about this min. The `-x` operand will potentially find less trailing bits due to the recursion limit in computeKnownBits. It has one more node to walk through. Using the tailing zeros bits based on which operand is `x` seems more reliable.
> I'm not sure about this min. The `-x` operand will potentially find less trailing bits due to the recursion limit in computeKnownBits. It has one more node to walk through. Using the tailing zeros bits based on which operand is `x` seems more reliable.

I think its possible for `-x` to find more bits if, for example, there is an `llvm.assume` on `-x` but but not on `x`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142271/new/

https://reviews.llvm.org/D142271



More information about the llvm-commits mailing list