<div dir="ltr">I mis-titled this commit. The enhancement for vectors is in *InstSimplify* not InstCombine, so this should have been:<br><br>
[InstSimplify] use m_APInt to allow icmp eq (op X, Y), C folds for splat constant vectors <br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 4, 2016 at 11:48 AM, Sanjay Patel via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: spatel<br>
Date: Thu Aug  4 12:48:04 2016<br>
New Revision: 277738<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=277738&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=277738&view=rev</a><br>
Log:<br>
[InstCombine] use m_APInt to allow icmp eq (op X, Y), C folds for splat constant vectors<br>
<br>
I'm removing a misplaced pair of more specific folds from InstCombine in this patch as well,<br>
so we know where those folds are happening in InstSimplify.<br>
<br>
<br>
Modified:<br>
    llvm/trunk/lib/Analysis/<wbr>InstructionSimplify.cpp<br>
    llvm/trunk/lib/Transforms/<wbr>InstCombine/<wbr>InstCombineCompares.cpp<br>
    llvm/trunk/test/Transforms/<wbr>InstSimplify/compare.ll<br>
<br>
Modified: llvm/trunk/lib/Analysis/<wbr>InstructionSimplify.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=277738&r1=277737&r2=277738&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>Analysis/InstructionSimplify.<wbr>cpp?rev=277738&r1=277737&r2=<wbr>277738&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/Analysis/<wbr>InstructionSimplify.cpp (original)<br>
+++ llvm/trunk/lib/Analysis/<wbr>InstructionSimplify.cpp Thu Aug  4 12:48:04 2016<br>
@@ -3121,17 +3121,16 @@ static Value *SimplifyICmpInst(unsigned<br>
   // If a bit is known to be zero for A and known to be one for B,<br>
   // then A and B cannot be equal.<br>
   if (ICmpInst::isEquality(Pred)) {<br>
-    if (ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {<br>
-      uint32_t BitWidth = CI->getBitWidth();<br>
+    const APInt *RHSVal;<br>
+    if (match(RHS, m_APInt(RHSVal))) {<br>
+      unsigned BitWidth = RHSVal->getBitWidth();<br>
       APInt LHSKnownZero(BitWidth, 0);<br>
       APInt LHSKnownOne(BitWidth, 0);<br>
       computeKnownBits(LHS, LHSKnownZero, LHSKnownOne, Q.DL, /*Depth=*/0, <a href="http://Q.AC" rel="noreferrer" target="_blank">Q.AC</a>,<br>
                        Q.CxtI, Q.DT);<br>
-      const APInt &RHSVal = CI->getValue();<br>
-      if (((LHSKnownZero & RHSVal) != 0) || ((LHSKnownOne & ~RHSVal) != 0))<br>
-        return Pred == ICmpInst::ICMP_EQ<br>
-                   ? ConstantInt::getFalse(CI-><wbr>getContext())<br>
-                   : ConstantInt::getTrue(CI-><wbr>getContext());<br>
+      if (((LHSKnownZero & *RHSVal) != 0) || ((LHSKnownOne & ~(*RHSVal)) != 0))<br>
+        return Pred == ICmpInst::ICMP_EQ ? ConstantInt::getFalse(ITy)<br>
+                                         : ConstantInt::getTrue(ITy);<br>
     }<br>
   }<br>
<br>
<br>
Modified: llvm/trunk/lib/Transforms/<wbr>InstCombine/<wbr>InstCombineCompares.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=277738&r1=277737&r2=277738&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>Transforms/InstCombine/<wbr>InstCombineCompares.cpp?rev=<wbr>277738&r1=277737&r2=277738&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/Transforms/<wbr>InstCombine/<wbr>InstCombineCompares.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/<wbr>InstCombine/<wbr>InstCombineCompares.cpp Thu Aug  4 12:48:04 2016<br>
@@ -2277,14 +2277,8 @@ Instruction *InstCombiner::foldICmpEqual<br>
     }<br>
     break;<br>
   case Instruction::Or:<br>
-    // If bits are being or'd in that are not present in the constant we<br>
-    // are comparing against, then the comparison could never succeed!<br>
     // FIXME: Vectors are excluded by ConstantInt.<br>
     if (ConstantInt *BOC = dyn_cast<ConstantInt>(BOp1)) {<br>
-      Constant *NotCI = ConstantExpr::getNot(RHS);<br>
-      if (!ConstantExpr::getAnd(BOC, NotCI)->isNullValue())<br>
-        return replaceInstUsesWith(ICI, Builder->getInt1(isICMP_NE));<br>
-<br>
       // Comparing if all bits outside of a constant mask are set?<br>
       // Replace (X | C) == -1 with (X & ~C) == ~C.<br>
       // This removes the -1 constant.<br>
@@ -2299,11 +2293,6 @@ Instruction *InstCombiner::foldICmpEqual<br>
   case Instruction::And:<br>
     // FIXME: Vectors are excluded by ConstantInt.<br>
     if (ConstantInt *BOC = dyn_cast<ConstantInt>(BOp1)) {<br>
-      // If bits are being compared against that are and'd out, then the<br>
-      // comparison can never succeed!<br>
-      if ((*RHSV & ~BOC->getValue()) != 0)<br>
-        return replaceInstUsesWith(ICI, Builder->getInt1(isICMP_NE));<br>
-<br>
       // If we have ((X & C) == C), turn it into ((X & C) != 0).<br>
       if (RHS == BOC && RHSV->isPowerOf2())<br>
         return new ICmpInst(isICMP_NE ? ICmpInst::ICMP_EQ : ICmpInst::ICMP_NE,<br>
<br>
Modified: llvm/trunk/test/Transforms/<wbr>InstSimplify/compare.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/compare.ll?rev=277738&r1=277737&r2=277738&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/test/<wbr>Transforms/InstSimplify/<wbr>compare.ll?rev=277738&r1=<wbr>277737&r2=277738&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/test/Transforms/<wbr>InstSimplify/compare.ll (original)<br>
+++ llvm/trunk/test/Transforms/<wbr>InstSimplify/compare.ll Thu Aug  4 12:48:04 2016<br>
@@ -1,3 +1,4 @@<br>
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py<br>
 ; RUN: opt < %s -instsimplify -S | FileCheck %s<br>
 target datalayout = "p:32:32"<br>
<br>
@@ -1017,9 +1018,7 @@ define i1 @icmp_eq_const(i32 %a) {<br>
 ; FIXME: Vectors should fold the same way.<br>
 define <2 x i1> @icmp_eq_const_vec(<2 x i32> %a) {<br>
 ; CHECK-LABEL: @icmp_eq_const_vec(<br>
-; CHECK-NEXT:    [[B:%.*]] = mul nsw <2 x i32> %a, <i32 -2, i32 -2><br>
-; CHECK-NEXT:    [[C:%.*]] = icmp eq <2 x i32> [[B]], <i32 1, i32 1><br>
-; CHECK-NEXT:    ret <2 x i1> [[C]]<br>
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer<br>
 ;<br>
   %b = mul nsw <2 x i32> %a, <i32 -2, i32 -2><br>
   %c = icmp eq <2 x i32> %b, <i32 1, i32 1><br>
@@ -1038,9 +1037,7 @@ define i1 @icmp_ne_const(i32 %a) {<br>
 ; FIXME: Vectors should fold the same way.<br>
 define <2 x i1> @icmp_ne_const_vec(<2 x i32> %a) {<br>
 ; CHECK-LABEL: @icmp_ne_const_vec(<br>
-; CHECK-NEXT:    [[B:%.*]] = mul nsw <2 x i32> %a, <i32 -2, i32 -2><br>
-; CHECK-NEXT:    [[C:%.*]] = icmp ne <2 x i32> [[B]], <i32 1, i32 1><br>
-; CHECK-NEXT:    ret <2 x i1> [[C]]<br>
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true><br>
 ;<br>
   %b = mul nsw <2 x i32> %a, <i32 -2, i32 -2><br>
   %c = icmp ne <2 x i32> %b, <i32 1, i32 1><br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>