1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

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

llvm-svn: 174932
This commit is contained in:
Arnold Schwaighofer 2013-02-12 02:40:37 +00:00
parent 1ecca5fd68
commit fafd6a4d28

View File

@ -80,6 +80,13 @@ CostModelAnalysis::runOnFunction(Function &F) {
return false; 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 { unsigned CostModelAnalysis::getInstructionCost(const Instruction *I) const {
if (!TTI) if (!TTI)
return -1; return -1;
@ -171,6 +178,17 @@ unsigned CostModelAnalysis::getInstructionCost(const Instruction *I) const {
return TTI->getVectorInstrCost(I->getOpcode(), return TTI->getVectorInstrCost(I->getOpcode(),
IE->getType(), Idx); 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: default:
// We don't have any information on this instruction. // We don't have any information on this instruction.
return -1; return -1;