[PATCH] D115755: [InstSimplify] Fold logic And to Zero

Stanislav Mekhanoshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 14 14:21:19 PST 2021


rampitec added inline comments.


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:2176
 
+  // ((A | B) ^ A ) & ((A | B) ^ B) --> 0
+  if (match(Op0, m_c_Xor(m_c_Or(m_Value(X), m_Value(Y)), m_Deferred(X))) &&
----------------
Could you please use X and Y in the comment, same as in the match?


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:2177
+  // ((A | B) ^ A ) & ((A | B) ^ B) --> 0
+  if (match(Op0, m_c_Xor(m_c_Or(m_Value(X), m_Value(Y)), m_Deferred(X))) &&
+      match(Op1, m_c_Xor(m_c_Or(m_Specific(X), m_Specific(Y)), m_Specific(Y))))
----------------
Commuted 'or' does not do anything, it will always match as just 'm_Or'.


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:2180
+    return Constant::getNullValue(Op0->getType());
+  // ((A | B) ^ B ) & ((A | B) ^ A) --> 0
+  if (match(Op0, m_c_Xor(m_c_Or(m_Value(X), m_Value(Y)), m_Deferred(Y))) &&
----------------
You could use 'm_CombineOr' for the LHS to select either deferred X or deferred Y. Then you do not need second expression.


================
Comment at: llvm/test/Transforms/InstSimplify/and.ll:168
   %or = or i71 %x, %y
   %xor1 = xor i71 %x, %or
   %xor2 = xor i71 %y, %or
----------------
'or' is more complex than the argument, the xor will be commuted.
See InstCombiner::getComplexity() for the details. Search for "thwart complexity-based canonicalization" in the llvm/test/Transforms/InstCombine directory for test coverage that works around it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115755



More information about the llvm-commits mailing list