[PATCH] D90674: [GlobalISel] Expand combine for (x & mask) -> x when (x & mask) == x
Mirko Brkusanin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 6 08:54:05 PST 2020
mbrkusanin added inline comments.
================
Comment at: llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp:2860-2861
- // Now, let's check that x & Mask == x. If this is true, then x & ~Mask == 0.
- return KB->maskedValueIsZero(Replacement, ~Mask);
+ // While we need to know all bits of the Mask, for x we only need the bits
+ // that go against zeros in Mask.
+ KnownBits LHSBits = KB->getKnownBits(LHS);
----------------
foad wrote:
> arsenm wrote:
> > Constants are canonicalized to the RHS, so you don't need KnownBits and can just directly get the constant.
> Or you can implement it generally and symmetrically, so that it works for non-constants as well as constants:
> X & Y -> X // if (XBits.Zero | YBits.One).isAllOnesValue()
> X & Y -> Y // if (XBits.One | YBits.Zero).isAllOnesValue()
@arsenm With KnownBits we can also catch cases like in test_and_non_const. Or the ones in combine-shift-of-shifted-logic.ll generated by D90223
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D90674/new/
https://reviews.llvm.org/D90674
More information about the llvm-commits
mailing list