[PATCH] D148986: [InstSimplify] with logical ops: (X | Y) ? 0 : X --> 0

Allen zhong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 22 02:40:34 PDT 2023


Allen created this revision.
Allen added reviewers: spatel, floatshadow, RKSimon, nikic, efriedma, xbolva00.
Herald added subscribers: hoy, StephenFan, hiraditya.
Herald added a project: All.
Allen requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

issue #62263


https://reviews.llvm.org/D148986

Files:
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/test/Transforms/InstSimplify/select.ll


Index: llvm/test/Transforms/InstSimplify/select.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/select.ll
+++ llvm/test/Transforms/InstSimplify/select.ll
@@ -1404,3 +1404,13 @@
   %cond = select <2 x i1> %tobool.not, <2 x i32> %mul, <2 x i32> zeroinitializer
   ret <2 x i32> %cond
 }
+
+define i32 @select_icmp_or(i32 noundef %a, i32 noundef %b) {
+; CHECK-LABEL: @select_icmp_or(
+; CHECK-NEXT:    ret i32 0
+;
+  %or = or i32 %a, %b
+  %tobool = icmp ne i32 %or, 0
+  %cond = select i1 %tobool, i32 0, i32 %a
+  ret i32 %cond
+}
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4725,6 +4725,13 @@
     }
   }
 
+  // (X | Y) ? 0 : X --> 0 (commuted 2 ways)
+  ICmpInst::Predicate Pred;
+  if (match(Cond,
+            m_ICmp(Pred, m_c_Or(m_Specific(FalseVal), m_Value()), m_Zero())) &&
+      match(TrueVal, m_ZeroInt()) && Pred == ICmpInst::ICMP_NE)
+    return TrueVal;
+
   // select ?, X, X -> X
   if (TrueVal == FalseVal)
     return TrueVal;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148986.516048.patch
Type: text/x-patch
Size: 1177 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230422/4131378b/attachment.bin>


More information about the llvm-commits mailing list