[PATCH] D90674: [GlobalISel] Expand combine for (x & mask) -> x when (x & mask) == x

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 3 07:05:19 PST 2020


foad 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);
----------------
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()


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90674



More information about the llvm-commits mailing list