Remove redundant test for vector-nature. Scan the vector first to see whether
authorNick Lewycky <nicholas@mxc.ca>
Sat, 20 Dec 2008 16:48:00 +0000 (16:48 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Sat, 20 Dec 2008 16:48:00 +0000 (16:48 +0000)
our optz'n will apply to it, then build the replacement vector only if needed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61279 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 41ed449958a513f002ebaf6734e48299f10afb16..5f22fd7ae237ffc7f084578af4aeff56d541a1fa 100644 (file)
@@ -3090,11 +3090,17 @@ Instruction *InstCombiner::visitSRem(BinaryOperator &I) {
   }
 
   // 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())