[llvm] r314360 - Revert r314017 '[InstCombine] Simplify check for RHS being a splat constant in foldICmpUsingKnownBits by just checking Op1Min==Op1Max rather than going through m_APInt.'

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 27 15:57:18 PDT 2017


Author: ctopper
Date: Wed Sep 27 15:57:18 2017
New Revision: 314360

URL: http://llvm.org/viewvc/llvm-project?rev=314360&view=rev
Log:
Revert r314017 '[InstCombine] Simplify check for RHS being a splat constant in foldICmpUsingKnownBits by just checking Op1Min==Op1Max rather than going through m_APInt.'

This reverts r314017 and similar code added in later commits. It seems to not work for pointer compares and is causing a bot failure for the last several days.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=314360&r1=314359&r2=314360&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Wed Sep 27 15:57:18 2017
@@ -4200,14 +4200,15 @@ Instruction *InstCombiner::foldICmpUsing
     if (Op1Min == Op0Max) // A <u B -> A != B if max(A) == min(B)
       return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
 
-    if (Op1Min == Op1Max) {
+    const APInt *CmpC;
+    if (match(Op1, m_APInt(CmpC))) {
       // A <u C -> A == C-1 if min(A)+1 == C
-      if (Op1Min == Op0Min + 1)
+      if (*CmpC == Op0Min + 1)
         return new ICmpInst(ICmpInst::ICMP_EQ, Op0,
-                            ConstantInt::get(Op0->getType(), Op1Min - 1));
+                            ConstantInt::get(Op1->getType(), *CmpC - 1));
       // X <u C --> X == 0, if the number of zero bits in the bottom of X
       // exceeds the log2 of C.
-      if (Op0Known.countMinTrailingZeros() >= Op1Min.ceilLogBase2())
+      if (Op0Known.countMinTrailingZeros() >= CmpC->ceilLogBase2())
         return new ICmpInst(ICmpInst::ICMP_EQ, Op0,
                             Constant::getNullValue(Op1->getType()));
     }
@@ -4221,45 +4222,50 @@ Instruction *InstCombiner::foldICmpUsing
     if (Op1Max == Op0Min) // A >u B -> A != B if min(A) == max(B)
       return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
 
-    if (Op1Min == Op1Max) {
+    const APInt *CmpC;
+    if (match(Op1, m_APInt(CmpC))) {
       // A >u C -> A == C+1 if max(a)-1 == C
-      if (Op1Min == Op0Max - 1)
+      if (*CmpC == Op0Max - 1)
         return new ICmpInst(ICmpInst::ICMP_EQ, Op0,
-                            ConstantInt::get(Op1->getType(), Op1Min + 1));
+                            ConstantInt::get(Op1->getType(), *CmpC + 1));
       // X >u C --> X != 0, if the number of zero bits in the bottom of X
       // exceeds the log2 of C.
-      if (Op0Known.countMinTrailingZeros() >= Op1Min.getActiveBits())
+      if (Op0Known.countMinTrailingZeros() >= CmpC->getActiveBits())
         return new ICmpInst(ICmpInst::ICMP_NE, Op0,
                             Constant::getNullValue(Op1->getType()));
     }
     break;
   }
-  case ICmpInst::ICMP_SLT:
+  case ICmpInst::ICMP_SLT: {
     if (Op0Max.slt(Op1Min)) // A <s B -> true if max(A) < min(C)
       return replaceInstUsesWith(I, ConstantInt::getTrue(I.getType()));
     if (Op0Min.sge(Op1Max)) // A <s B -> false if min(A) >= max(C)
       return replaceInstUsesWith(I, ConstantInt::getFalse(I.getType()));
     if (Op1Min == Op0Max) // A <s B -> A != B if max(A) == min(B)
       return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
-    if (Op1Min == Op1Max) { // Constant RHS
-      if (Op1Min == Op0Min + 1) // A <s C -> A == C-1 if min(A)+1 == C
+    const APInt *CmpC;
+    if (match(Op1, m_APInt(CmpC))) {
+      if (*CmpC == Op0Min + 1) // A <s C -> A == C-1 if min(A)+1 == C
         return new ICmpInst(ICmpInst::ICMP_EQ, Op0,
-                            ConstantInt::get(Op1->getType(), Op1Min - 1));
+                            ConstantInt::get(Op1->getType(), *CmpC - 1));
     }
     break;
-  case ICmpInst::ICMP_SGT:
+  }
+  case ICmpInst::ICMP_SGT: {
     if (Op0Min.sgt(Op1Max)) // A >s B -> true if min(A) > max(B)
       return replaceInstUsesWith(I, ConstantInt::getTrue(I.getType()));
     if (Op0Max.sle(Op1Min)) // A >s B -> false if max(A) <= min(B)
       return replaceInstUsesWith(I, ConstantInt::getFalse(I.getType()));
     if (Op1Max == Op0Min) // A >s B -> A != B if min(A) == max(B)
       return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
-    if (Op1Min == Op1Max) { // Constant RHS
-      if (Op1Min == Op0Max - 1) // A >s C -> A == C+1 if max(A)-1 == C
+    const APInt *CmpC;
+    if (match(Op1, m_APInt(CmpC))) {
+      if (*CmpC == Op0Max - 1) // A >s C -> A == C+1 if max(A)-1 == C
         return new ICmpInst(ICmpInst::ICMP_EQ, Op0,
-                            ConstantInt::get(Op1->getType(), Op1Min + 1));
+                            ConstantInt::get(Op1->getType(), *CmpC + 1));
     }
     break;
+  }
   case ICmpInst::ICMP_SGE:
     assert(!isa<ConstantInt>(Op1) && "ICMP_SGE with ConstantInt not folded!");
     if (Op0Min.sge(Op1Max)) // A >=s B -> true if min(A) >= max(B)




More information about the llvm-commits mailing list