[llvm] r201344 - Reduce code duplication resulting from the ConstantVector/ConstantDataVector split.

Benjamin Kramer benny.kra at googlemail.com
Thu Feb 13 08:48:39 PST 2014


Author: d0k
Date: Thu Feb 13 10:48:38 2014
New Revision: 201344

URL: http://llvm.org/viewvc/llvm-project?rev=201344&view=rev
Log:
Reduce code duplication resulting from the ConstantVector/ConstantDataVector split.

No intended functionality change.

Modified:
    llvm/trunk/lib/Analysis/CostModel.cpp
    llvm/trunk/lib/Transforms/Vectorize/BBVectorize.cpp
    llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp

Modified: llvm/trunk/lib/Analysis/CostModel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CostModel.cpp?rev=201344&r1=201343&r2=201344&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CostModel.cpp (original)
+++ llvm/trunk/lib/Analysis/CostModel.cpp Thu Feb 13 10:48:38 2014
@@ -99,17 +99,9 @@ static TargetTransformInfo::OperandValue
     TargetTransformInfo::OK_AnyValue;
 
   // Check for a splat of a constant or for a non uniform vector of constants.
-  ConstantDataVector *CDV = 0;
-  if ((CDV = dyn_cast<ConstantDataVector>(V))) {
+  if (isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) {
     OpInfo = TargetTransformInfo::OK_NonUniformConstantValue;
-    if (CDV->getSplatValue() != NULL)
-      OpInfo = TargetTransformInfo::OK_UniformConstantValue;
-  }
-
-  ConstantVector *CV = 0;
-  if ((CV = dyn_cast<ConstantVector>(V))) {
-    OpInfo = TargetTransformInfo::OK_NonUniformConstantValue;
-    if (CV->getSplatValue() != NULL)
+    if (cast<Constant>(V)->getSplatValue() != NULL)
       OpInfo = TargetTransformInfo::OK_UniformConstantValue;
   }
 

Modified: llvm/trunk/lib/Transforms/Vectorize/BBVectorize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/BBVectorize.cpp?rev=201344&r1=201343&r2=201344&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/BBVectorize.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/BBVectorize.cpp Thu Feb 13 10:48:38 2014
@@ -1043,22 +1043,13 @@ namespace {
           // of constants.
           Value *IOp = I->getOperand(1);
           Value *JOp = J->getOperand(1);
-          if (ConstantDataVector *CDVI = dyn_cast<ConstantDataVector>(IOp)) {
-            if (ConstantDataVector *CDVJ = dyn_cast<ConstantDataVector>(JOp)) {
-              Op2VK = TargetTransformInfo::OK_NonUniformConstantValue;
-              Constant *SplatValue = CDVI->getSplatValue();
-              if (SplatValue != NULL && SplatValue == CDVJ->getSplatValue())
-                Op2VK = TargetTransformInfo::OK_UniformConstantValue;
-            }
-          }
-
-          if (ConstantVector *CVI = dyn_cast<ConstantVector>(IOp)) {
-            if (ConstantVector *CVJ = dyn_cast<ConstantVector>(JOp)) {
-              Op2VK = TargetTransformInfo::OK_NonUniformConstantValue;
-              Constant *SplatValue = CVI->getSplatValue();
-              if (SplatValue != NULL && SplatValue == CVJ->getSplatValue())
-                Op2VK = TargetTransformInfo::OK_UniformConstantValue;
-            }
+          if ((isa<ConstantVector>(IOp) || isa<ConstantDataVector>(IOp)) &&
+              (isa<ConstantVector>(JOp) || isa<ConstantDataVector>(JOp))) {
+            Op2VK = TargetTransformInfo::OK_NonUniformConstantValue;
+            Constant *SplatValue = cast<Constant>(IOp)->getSplatValue();
+            if (SplatValue != NULL &&
+                SplatValue == cast<Constant>(JOp)->getSplatValue())
+              Op2VK = TargetTransformInfo::OK_UniformConstantValue;
           }
         }
       }

Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=201344&r1=201343&r2=201344&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Thu Feb 13 10:48:38 2014
@@ -5496,13 +5496,9 @@ LoopVectorizationCostModel::getInstructi
     // Check for a splat of a constant or for a non uniform vector of constants.
     if (isa<ConstantInt>(Op2))
       Op2VK = TargetTransformInfo::OK_UniformConstantValue;
-    else if (ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(Op2)) {
+    else if (isa<ConstantVector>(Op2) || isa<ConstantDataVector>(Op2)) {
       Op2VK = TargetTransformInfo::OK_NonUniformConstantValue;
-      if (CDV->getSplatValue() != NULL)
-        Op2VK = TargetTransformInfo::OK_UniformConstantValue;
-    } else if (ConstantVector *CV = dyn_cast<ConstantVector>(Op2)) {
-      Op2VK = TargetTransformInfo::OK_NonUniformConstantValue;
-      if (CV->getSplatValue() != NULL)
+      if (cast<Constant>(Op2)->getSplatValue() != NULL)
         Op2VK = TargetTransformInfo::OK_UniformConstantValue;
     }
 





More information about the llvm-commits mailing list