[PATCH] D153148: [InstCombine] Fold `(-1 + A) & B` into `A ? 0 : B` where A is effectively a bool
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 24 11:37:18 PDT 2023
nikic added inline comments.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:2601
A->getType()->isIntOrIntVectorTy(1))
- return SelectInst::Create(A, Constant::getNullValue(Ty), Op0);
+ return SelectInst::Create(A, Constant::getNullValue(Ty), B);
+
----------------
Please land this code cleanup as a separate NFC commit.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:2609
+ return SelectInst::Create(A, Constant::getNullValue(Ty), B);
+ if (computeKnownBits(A, /* Depth */ 0, &I).countMaxActiveBits() <= 1) {
+ return SelectInst::Create(
----------------
goldstein.w.n wrote:
> `computeKnownBits(A, /* Depth */ 0, &I).countMaxActiveBits() <= 1` -> `isKnownToBeAPowerOfTwo(A,..., /*OrZero*/true, ...)`
That's not the same thing though? The current check only allows 0 and 1, which result in -1 and 0 after the add. If it's just any power of two we have 0 and 2^x instead, which become -1 and 2^x-1.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D153148/new/
https://reviews.llvm.org/D153148
More information about the llvm-commits
mailing list