[PATCH] D142271: [ValueTracking] Add KnownBits patterns `xor(x, x - 1)` and `and(x, -x)` for knowing upper bits to be zero
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 26 05:37:53 PST 2023
nikic added inline comments.
================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:1093
+ if (match(I, m_c_BinOp(m_Value(X), m_Neg(m_Deferred(X))))) {
+ if (Known.countMaxTrailingZeros() <= Known2.countMaxTrailingZeros())
+ Known = Known.blsi();
----------------
Add a comment that as `-(-x) == x`, we can view this as a blsi operation on either operand, and pick whichever produces the best result.
================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:1096
+ else
+ Known = Known2.blsi();
+ }
----------------
break here? Don't think we want to fall through.
================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:1134
+ if ((!Known.One.isZero() || !Known2.One.isZero()) &&
+ match(I, m_c_BinOp(m_Value(X), m_c_Add(m_Deferred(X), m_APInt(C)))) &&
+ C->isAllOnes()) {
----------------
`m_APInt(C)` -> `m_AllOnes()`.
================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:1136
+ C->isAllOnes()) {
+ const KnownBits &XBits = I->getOperand(0) == X ? Known2 : Known;
+ Known = XBits.blsmsk();
----------------
Shouldn't this be `? Known : Known2`? We want the known bits of X, not of X-1.
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