summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/CostModel.cpp
diff options
context:
space:
mode:
authorArnold Schwaighofer <aschwaighofer@apple.com>2013-04-04 23:26:21 +0000
committerArnold Schwaighofer <aschwaighofer@apple.com>2013-04-04 23:26:21 +0000
commitb977387112a6b89fa5ad987016194542377cdc99 (patch)
treec1f2453e80639afaffe147824826304139fbdfce /llvm/lib/Analysis/CostModel.cpp
parentbdcb4464e2bc50cc24fd5d81018c1f7ab4695f1b (diff)
downloadbcm5719-llvm-b977387112a6b89fa5ad987016194542377cdc99.tar.gz
bcm5719-llvm-b977387112a6b89fa5ad987016194542377cdc99.zip
CostModel: Add parameter to instruction cost to further classify operand values
On certain architectures we can support efficient vectorized version of instructions if the operand value is uniform (splat) or a constant scalar. An example of this is a vector shift on x86. We can efficiently support for (i = 0 ; i < ; i += 4) w[0:3] = v[0:3] << <2, 2, 2, 2> but not for (i = 0; i < ; i += 4) w[0:3] = v[0:3] << x[0:3] This patch adds a parameter to getArithmeticInstrCost to further qualify operand values as uniform or uniform constant. Targets can then choose to return a different cost for instructions with such operand values. A follow-up commit will test this feature on x86. radar://13576547 llvm-svn: 178807
Diffstat (limited to 'llvm/lib/Analysis/CostModel.cpp')
-rw-r--r--llvm/lib/Analysis/CostModel.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/CostModel.cpp b/llvm/lib/Analysis/CostModel.cpp
index df70d157b41..98a7780ad9a 100644
--- a/llvm/lib/Analysis/CostModel.cpp
+++ b/llvm/lib/Analysis/CostModel.cpp
@@ -88,6 +88,23 @@ static bool isReverseVectorMask(SmallVector<int, 16> &Mask) {
return true;
}
+static TargetTransformInfo::OperandValueKind getOperandInfo(Value *V) {
+ TargetTransformInfo::OperandValueKind OpInfo =
+ TargetTransformInfo::OK_AnyValue;
+
+ // Check for a splat of a constant.
+ ConstantDataVector *CDV = 0;
+ if ((CDV = dyn_cast<ConstantDataVector>(V)))
+ if (CDV->getSplatValue() != NULL)
+ OpInfo = TargetTransformInfo::OK_UniformConstantValue;
+ ConstantVector *CV = 0;
+ if ((CV = dyn_cast<ConstantVector>(V)))
+ if (CV->getSplatValue() != NULL)
+ OpInfo = TargetTransformInfo::OK_UniformConstantValue;
+
+ return OpInfo;
+}
+
unsigned CostModelAnalysis::getInstructionCost(const Instruction *I) const {
if (!TTI)
return -1;
@@ -121,7 +138,12 @@ unsigned CostModelAnalysis::getInstructionCost(const Instruction *I) const {
case Instruction::And:
case Instruction::Or:
case Instruction::Xor: {
- return TTI->getArithmeticInstrCost(I->getOpcode(), I->getType());
+ TargetTransformInfo::OperandValueKind Op1VK =
+ getOperandInfo(I->getOperand(0));
+ TargetTransformInfo::OperandValueKind Op2VK =
+ getOperandInfo(I->getOperand(1));
+ return TTI->getArithmeticInstrCost(I->getOpcode(), I->getType(), Op1VK,
+ Op2VK);
}
case Instruction::Select: {
const SelectInst *SI = cast<SelectInst>(I);
OpenPOWER on IntegriCloud