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

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 3 06:40:12 PST 2020


arsenm added inline comments.


================
Comment at: llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h:426
                               std::tuple<Register, int64_t> &MatchInfo);
+
   /// \return true if \p MI is a G_AND instruction whose RHS is a mask where
----------------
Unnecessary whitespace change


================
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);
----------------
Constants are canonicalized to the RHS, so you don't need KnownBits and can just directly get the constant.


================
Comment at: llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp:2873
+  if (RHSBits.isConstant() && canReplaceReg(AndDst, LHS, MRI) &&
+      RHSBits.Zero.isSubsetOf(LHSBits.Zero)) {
+    Replacement = LHS;
----------------
MaskedValueIsZero helper like the DAG?


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