[PATCH] D157309: [ValueTracking] Do more thorough non-zero check in `isKnownToBePowerOfTwo` when `OrZero` is no set.

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 9 10:10:14 PDT 2023


goldstein.w.n added inline comments.


================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:2049
   case Instruction::Shl:
-    if (OrZero || Q.IIQ.hasNoUnsignedWrap(I) || Q.IIQ.hasNoSignedWrap(I))
-      return isKnownToBeAPowerOfTwo(I->getOperand(0), OrZero, Depth, Q);
----------------
goldstein.w.n wrote:
> nikic wrote:
> > Would it make sense to preserve the flag checks? I think isKnownNonZero will be able to prove the same result, but in a more roundabout way (it can't just check the flags, it will also have to prove non-zero operands etc).
> I think for `shl` you are right, `IPSCCP` will propagate `nuw` in all the cases I think `isKnownNonZero` helps here.
> For `lshr` however the equivilent logic is missing. I take it you would prefer fixing this with a patch to `IPSCCP`?
Think actually best in InstCombine, IPSCCP uses ranges which isn't so useful for checking if a remainder is zero. Think computeKnownBits makes more sense for this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157309



More information about the llvm-commits mailing list