[PATCH] D113861: [InstSimplify] Fold A|B | (A^B) --> A|B

Mehrnoosh Heidarpour via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 15 05:34:02 PST 2021


MehrHeidar added inline comments.


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:2270
+  // (B | A) | (A ^ B) --> B | A
+  if (match(Op1, m_Xor(m_Value(A), m_Value(B))) &&
+      match(Op0, m_c_Or(m_Specific(A), m_Specific(B))))
----------------
foad wrote:
> Just curious: don't we have matchers that will automatically match both the swapped and non-swapped forms of a commutative op?
I think there are matchers which  can match both swapped operands of a commutive operands, I assume the `c` letter in `m_c_Xor` and `m_c_Or` for instance is standing for `commutive`. However, here I needed to match the operands of outer `or` instruction. So, I needed the commuted version as well. I am not sure, if there is any other way of doing that, because in all other folding cases implemented `InstSimplify`, the commuted version is added.

Also, I have added the lit test cases here D113860, to pre-commit and rebase this patch so we can show the changes.

Thanks for your comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113861



More information about the llvm-commits mailing list