[PATCH] D112338: [InstCombine] Fold `(~(a | b) & c) | ~(a | c)` into `~((b & c) | a)`

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 28 11:26:50 PDT 2021


spatel added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:2800-2801
+  // (~(A | B) & C) | ~(A | C) --> ~((B & C) | A)
+  if (match(Op0, m_OneUse(m_c_And(m_OneUse(m_Not(m_Or(m_Value(A), m_Value(B)))),
+                                  m_Value(C))))) {
+    if (match(Op1, m_OneUse(m_Not(m_c_Or(m_Specific(A), m_Specific(C))))))
----------------
This one's a little smaller/easier than the other patch. If we have one-use checks on Op0 (the 'and') and Op1 (the 'not' of RHS), then this transform should be fine. So we don't need the m_OneUse on the inner 'not' here.


================
Comment at: llvm/test/Transforms/InstCombine/and-xor-or.ll:1030
   %not2 = xor i32 %or2, -1
   %and = and i32 %b, %not2
   %or3 = or i32 %and, %not1
----------------
Add an instruction to prevent this from commuting.


================
Comment at: llvm/test/Transforms/InstCombine/and-xor-or.ll:1035
 
 define i32 @or_and_not_not_commute2(i32 %a, i32 %b, i32 %c) {
 ; CHECK-LABEL: @or_and_not_not_commute2(
----------------
This is identical to the first test?


================
Comment at: llvm/test/Transforms/InstCombine/and-xor-or.ll:1092
 
 define i32 @or_and_not_not_commute5(i32 %a, i32 %b, i32 %c) {
 ; CHECK-LABEL: @or_and_not_not_commute5(
----------------
Flipped the wrong set of operands? This is effectively the same as "commute2".

The final 'or' doesn't really matter (but it's fine to commute that just to be sure).


================
Comment at: llvm/test/Transforms/InstCombine/and-xor-or.ll:1125
   %not2 = xor i32 %or2, -1
   %and = and i32 %b, %not2
   %or3 = or i32 %and, %not1
----------------
Add an instruction to prevent this from commuting.


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

https://reviews.llvm.org/D112338



More information about the llvm-commits mailing list