From: Arnold Schwaighofer Date: Tue, 12 Feb 2013 02:40:37 +0000 (+0000) Subject: Cost model: Add check for reverse shuffles to CostModel analysis X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4fc6484ee2439a9506d525ca757171e0ecc07744;p=oota-llvm.git 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174932 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CostModel.cpp b/lib/Analysis/CostModel.cpp index 8435e397077..44684a9685b 100644 --- a/lib/Analysis/CostModel.cpp +++ b/lib/Analysis/CostModel.cpp @@ -80,6 +80,13 @@ CostModelAnalysis::runOnFunction(Function &F) { return false; } +static bool isReverseVectorMask(SmallVector &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::getInstructionCost(const Instruction *I) const { return TTI->getVectorInstrCost(I->getOpcode(), IE->getType(), Idx); } + case Instruction::ShuffleVector: { + const ShuffleVectorInst *Shuffle = cast(I); + Type *VecTypOp0 = Shuffle->getOperand(0)->getType(); + unsigned NumVecElems = VecTypOp0->getVectorNumElements(); + SmallVector 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;