[PATCH] D153148: [InstCombine] Fold `(-1 + A) & B` into `A ? 0 : B` where A is effectively a bool
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 9 17:30:45 PDT 2023
goldstein.w.n 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);
+
----------------
nikic wrote:
> Please land this code cleanup as a separate NFC commit.
This comment is outstanding.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:2604
+ // (-1 + A) & B --> A ? 0 : B where A is effectively a bool (zext of i1/<N x
+ // i1>, or inst with !range {0, 2}).
+ if (match(&I, m_c_And(m_OneUse(m_Add(m_ZExtOrSelf(m_Value(A)), m_AllOnes())),
----------------
`i1`/`!range {0,2}` isn't really the necessary condition. The necessary condition is `A` is `0` or `1` which can be proven in a lot more cases.
Please also update the title/summary with this precondition of `A` being 0/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