[PATCH] D50604: [InstCombine] Replace call to haveNoCommonBitsSet in visitXor with just the special case that doesn't use computeKnownBits.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 11 21:51:35 PDT 2018


craig.topper created this revision.
craig.topper added reviewers: spatel, lebedev.ri.

computeKnownBits is expensive. The cases that would be detected by the computeKnownBits portion of haveNoCommonBitsSet were already handled by the earlier call to SimplifyDemandedInstructionBits.


Repository:
  rL LLVM

https://reviews.llvm.org/D50604

Files:
  lib/Transforms/InstCombine/InstCombineAndOrXor.cpp


Index: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -2507,9 +2507,17 @@
   if (Value *V = SimplifyBSwap(I, Builder))
     return replaceInstUsesWith(I, V);
 
-  // A^B --> A|B iff A and B have no bits set in common.
   Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
-  if (haveNoCommonBitsSet(Op0, Op1, DL, &AC, &I, &DT))
+
+  // Fold (X & M) ^ (Y & ~M) -> (X & M) | (Y & ~M)
+  // This it a special case in haveNoCommonBitsSet, but the commputeKnownBits
+  // calls in there are unnecessary as SimplifyDemandedInstructionBits should
+  // have already taken care of those cases.
+  Value *M;
+  if ((match(Op0, m_c_And(m_Not(m_Value(M)), m_Value())) &&
+       match(Op1, m_c_And(m_Specific(M), m_Value()))) ||
+      (match(Op1, m_c_And(m_Not(m_Value(M)), m_Value())) &&
+       match(Op0, m_c_And(m_Specific(M), m_Value()))))
     return BinaryOperator::CreateOr(Op0, Op1);
 
   // Apply DeMorgan's Law for 'nand' / 'nor' logic with an inverted operand.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50604.160250.patch
Type: text/x-patch
Size: 1151 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180812/122f634b/attachment.bin>


More information about the llvm-commits mailing list