[llvm] r174932 - Cost model: Add check for reverse shuffles to CostModel analysis
Arnold Schwaighofer
aschwaighofer at apple.com
Mon Feb 11 18:40:38 PST 2013
Author: arnolds
Date: Mon Feb 11 20:40:37 2013
New Revision: 174932
URL: http://llvm.org/viewvc/llvm-project?rev=174932&view=rev
Log:
Cost model: Add check for reverse shuffles to CostModel analysis
Check for reverse shuffles in the CostModel analysis pass and query
TargetTransform info accordingly. This allows us we can write test cases for
reverse shuffles.
radar://13171406
Modified:
llvm/trunk/lib/Analysis/CostModel.cpp
Modified: llvm/trunk/lib/Analysis/CostModel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CostModel.cpp?rev=174932&r1=174931&r2=174932&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CostModel.cpp (original)
+++ llvm/trunk/lib/Analysis/CostModel.cpp Mon Feb 11 20:40:37 2013
@@ -80,6 +80,13 @@ CostModelAnalysis::runOnFunction(Functio
return false;
}
+static bool isReverseVectorMask(SmallVector<int, 16> &Mask) {
+ for (unsigned i = 0, MaskSize = Mask.size(); i < MaskSize; ++i)
+ if (Mask[i] > 0 && Mask[i] != (int)(MaskSize - 1 - i))
+ return false;
+ return true;
+}
+
unsigned CostModelAnalysis::getInstructionCost(const Instruction *I) const {
if (!TTI)
return -1;
@@ -171,6 +178,17 @@ unsigned CostModelAnalysis::getInstructi
return TTI->getVectorInstrCost(I->getOpcode(),
IE->getType(), Idx);
}
+ case Instruction::ShuffleVector: {
+ const ShuffleVectorInst *Shuffle = cast<ShuffleVectorInst>(I);
+ Type *VecTypOp0 = Shuffle->getOperand(0)->getType();
+ unsigned NumVecElems = VecTypOp0->getVectorNumElements();
+ SmallVector<int, 16> Mask = Shuffle->getShuffleMask();
+
+ if (NumVecElems == Mask.size() && isReverseVectorMask(Mask))
+ return TTI->getShuffleCost(TargetTransformInfo::SK_Reverse, VecTypOp0, 0,
+ 0);
+ return -1;
+ }
default:
// We don't have any information on this instruction.
return -1;
More information about the llvm-commits
mailing list