[llvm-commits] [llvm] r61279 - /llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Nick Lewycky nicholas at mxc.ca
Sat Dec 20 08:48:01 PST 2008


Author: nicholas
Date: Sat Dec 20 10:48:00 2008
New Revision: 61279

URL: http://llvm.org/viewvc/llvm-project?rev=61279&view=rev
Log:
Remove redundant test for vector-nature. Scan the vector first to see whether
our optz'n will apply to it, then build the replacement vector only if needed.

Modified:
    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=61279&r1=61278&r2=61279&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Sat Dec 20 10:48:00 2008
@@ -3090,11 +3090,17 @@
   }
 
   // If it's a constant vector, flip any negative values positive.
-  if (isa<VectorType>(I.getType())) {
-    if (ConstantVector *RHSV = dyn_cast<ConstantVector>(Op1)) {
-      unsigned VWidth = RHSV->getNumOperands();
-      std::vector<Constant *> Elts(VWidth);
+  if (ConstantVector *RHSV = dyn_cast<ConstantVector>(Op1)) {
+    unsigned VWidth = RHSV->getNumOperands();
+
+    bool hasNegative = false;
+    for (unsigned i = 0; !hasNegative && i != VWidth; ++i)
+      if (ConstantInt *RHS = dyn_cast<ConstantInt>(RHSV->getOperand(i)))
+        if (RHS->getValue().isNegative())
+          hasNegative = true;
 
+    if (hasNegative) {
+      std::vector<Constant *> Elts(VWidth);
       for (unsigned i = 0; i != VWidth; ++i) {
         if (ConstantInt *RHS = dyn_cast<ConstantInt>(RHSV->getOperand(i))) {
           if (RHS->getValue().isNegative())





More information about the llvm-commits mailing list