[llvm] r316265 - [ValueTracking] Simplify the known bits code for constant vectors a little.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 21 09:35:39 PDT 2017


Author: ctopper
Date: Sat Oct 21 09:35:39 2017
New Revision: 316265

URL: http://llvm.org/viewvc/llvm-project?rev=316265&view=rev
Log:
[ValueTracking] Simplify the known bits code for constant vectors a little.

Neither of these cases really require a temporary APInt outside the loop. For the ConstantDataSequential case the APInt will never be larger than 64-bits so its fine to just call getElementAsAPInt. For ConstantVector we can get the APInt by reference and only make a copy where the inversion is needed.

Modified:
    llvm/trunk/lib/Analysis/ValueTracking.cpp

Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=316265&r1=316264&r2=316265&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Sat Oct 21 09:35:39 2017
@@ -1507,9 +1507,8 @@ void computeKnownBits(const Value *V, Kn
     // We know that CDS must be a vector of integers. Take the intersection of
     // each element.
     Known.Zero.setAllBits(); Known.One.setAllBits();
-    APInt Elt(BitWidth, 0);
     for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
-      Elt = CDS->getElementAsInteger(i);
+      APInt Elt = CDS->getElementAsAPInt(i);
       Known.Zero &= ~Elt;
       Known.One &= Elt;
     }
@@ -1520,7 +1519,6 @@ void computeKnownBits(const Value *V, Kn
     // We know that CV must be a vector of integers. Take the intersection of
     // each element.
     Known.Zero.setAllBits(); Known.One.setAllBits();
-    APInt Elt(BitWidth, 0);
     for (unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) {
       Constant *Element = CV->getAggregateElement(i);
       auto *ElementCI = dyn_cast_or_null<ConstantInt>(Element);
@@ -1528,7 +1526,7 @@ void computeKnownBits(const Value *V, Kn
         Known.resetAll();
         return;
       }
-      Elt = ElementCI->getValue();
+      const APInt &Elt = ElementCI->getValue();
       Known.Zero &= ~Elt;
       Known.One &= Elt;
     }




More information about the llvm-commits mailing list