[llvm] a8fcb51 - [InstSimplify] allow poison/undef in constant match for "C - X ==/!= X -> false/true"

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 6 05:19:51 PDT 2022


Author: Sanjay Patel
Date: 2022-09-06T08:19:30-04:00
New Revision: a8fcb512426316080b94702538061914bb4a6bd1

URL: https://github.com/llvm/llvm-project/commit/a8fcb512426316080b94702538061914bb4a6bd1
DIFF: https://github.com/llvm/llvm-project/commit/a8fcb512426316080b94702538061914bb4a6bd1.diff

LOG: [InstSimplify] allow poison/undef in constant match for "C - X ==/!= X -> false/true"

This fold was added with 5e9522c311dd, but over-specified.
We can assume that an undef element is an odd number:
https://alive2.llvm.org/ce/z/djQmWU

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp
    llvm/test/Transforms/InstSimplify/icmp.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 27ec7a0f350f..eebb5f1f0915 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -3128,14 +3128,9 @@ static Value *simplifyICmpWithBinOpOnLHS(CmpInst::Predicate Pred,
 
   // (sub C, X) == X, C is odd  --> false
   // (sub C, X) != X, C is odd  --> true
-  if (match(LBO, m_Sub(m_APInt(C), m_Specific(RHS)))) {
-    if ((*C & 1) == 1) {
-      if (Pred == CmpInst::ICMP_EQ)
-        return getFalse(ITy);
-      if (Pred == CmpInst::ICMP_NE)
-        return getTrue(ITy);
-    }
-  }
+  if (match(LBO, m_Sub(m_APIntAllowUndef(C), m_Specific(RHS))) &&
+      (*C & 1) == 1 && ICmpInst::isEquality(Pred))
+    return (Pred == ICmpInst::ICMP_EQ) ? getFalse(ITy) : getTrue(ITy);
 
   return nullptr;
 }

diff  --git a/llvm/test/Transforms/InstSimplify/icmp.ll b/llvm/test/Transforms/InstSimplify/icmp.ll
index c6d2f3c03beb..6f0a3fa52c86 100644
--- a/llvm/test/Transforms/InstSimplify/icmp.ll
+++ b/llvm/test/Transforms/InstSimplify/icmp.ll
@@ -241,9 +241,7 @@ define <2 x i1> @sub_odd(<2 x i8> %x) {
 
 define <2 x i1> @sub_odd_poison(<2 x i8> %x) {
 ; CHECK-LABEL: @sub_odd_poison(
-; CHECK-NEXT:    [[SUB:%.*]] = sub <2 x i8> <i8 poison, i8 1>, [[X:%.*]]
-; CHECK-NEXT:    [[CMP:%.*]] = icmp ne <2 x i8> [[SUB]], [[X]]
-; CHECK-NEXT:    ret <2 x i1> [[CMP]]
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
 ;
   %sub = sub <2 x i8> <i8 poison, i8 1>, %x
   %cmp = icmp ne <2 x i8> %sub, %x


        


More information about the llvm-commits mailing list