[PATCH] D114996: Add logic `or` fold

Mehrnoosh Heidarpour via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 2 13:51:15 PST 2021


MehrHeidar created this revision.
Herald added a subscriber: hiraditya.
MehrHeidar requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Add logic `or` fold:    `(A ^ B) | (~A | B) --> -1`

https://alive2.llvm.org/ce/z/PMtdYB

Test cases with base results are added in D114992 <https://reviews.llvm.org/D114992>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114996

Files:
  llvm/lib/Analysis/InstructionSimplify.cpp


Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -2226,6 +2226,12 @@
       match(Y, m_c_Or(m_Specific(A), m_Specific(B))))
     return ConstantInt::getAllOnesValue(Ty);
 
+  // (A ^ B) | (~A | B) --> -1
+  // (A ^ B) | (~B | A) --> -1
+  if (match(X, m_c_Or(m_Not(m_Value(A)), m_Value(B))) &&
+      match(Y, m_c_Xor(m_Specific(A), m_Specific(B))))
+    return ConstantInt::getAllOnesValue(Ty);
+
   return nullptr;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114996.391449.patch
Type: text/x-patch
Size: 585 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211202/65318363/attachment.bin>


More information about the llvm-commits mailing list