aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Vectorize/LoopVectorize.cpp
diff options
context:
space:
mode:
authorNadav Rotem <nrotem@apple.com>2012-12-03 22:46:31 +0000
committerNadav Rotem <nrotem@apple.com>2012-12-03 22:46:31 +0000
commitfa72ee729a989ff340672034fd77832c1fd76326 (patch)
treea946fe00f548243e9df4caafb38e35a1b16aa5b4 /lib/Transforms/Vectorize/LoopVectorize.cpp
parent303da1baf2a90d18a709f29f4f7cd0e1962be5f9 (diff)
IF-conversion: teach the cost-model how to grade if-converted loops.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169171 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Vectorize/LoopVectorize.cpp')
-rw-r--r--lib/Transforms/Vectorize/LoopVectorize.cpp41
1 files changed, 26 insertions, 15 deletions
diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp
index ecf19b721d..efbf0fd7cf 100644
--- a/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -321,6 +321,10 @@ public:
/// Returns the induction variables found in the loop.
InductionList *getInductionVars() { return &Inductions; }
+ /// Return true if the block BB needs to be predicated in order for the loop
+ /// to be vectorized.
+ bool blockNeedsPredication(BasicBlock *BB);
+
/// Check if this pointer is consecutive when vectorizing. This happens
/// when the last index of the GEP is the induction variable, or that the
/// pointer itself is an induction variable.
@@ -354,10 +358,6 @@ private:
/// Collect the variables that need to stay uniform after vectorization.
void collectLoopUniforms();
- /// Return true if the block BB needs to be predicated in order for the loop
- /// to be vectorized.
- bool blockNeedsPredication(BasicBlock *BB);
-
/// return true if all of the instructions in the block can be speculatively
/// executed.
bool blockCanBePredicated(BasicBlock *BB);
@@ -2064,19 +2064,29 @@ LoopVectorizationCostModel::findBestVectorizationFactor(unsigned VF) {
}
unsigned LoopVectorizationCostModel::expectedCost(unsigned VF) {
- // We can only estimate the cost of single basic block loops.
- assert(1 == TheLoop->getNumBlocks() && "Too many blocks in loop");
-
- BasicBlock *BB = TheLoop->getHeader();
unsigned Cost = 0;
- // For each instruction in the old loop.
- for (BasicBlock::iterator it = BB->begin(), e = BB->end(); it != e; ++it) {
- Instruction *Inst = it;
- unsigned C = getInstructionCost(Inst, VF);
- Cost += C;
- DEBUG(dbgs() << "LV: Found an estimated cost of "<< C <<" for VF "<< VF <<
- " For instruction: "<< *Inst << "\n");
+ // For each block.
+ for (Loop::block_iterator bb = TheLoop->block_begin(),
+ be = TheLoop->block_end(); bb != be; ++bb) {
+ unsigned BlockCost = 0;
+ BasicBlock *BB = *bb;
+
+ // For each instruction in the old loop.
+ for (BasicBlock::iterator it = BB->begin(), e = BB->end(); it != e; ++it) {
+
+ unsigned C = getInstructionCost(it, VF);
+ Cost += C;
+ DEBUG(dbgs() << "LV: Found an estimated cost of "<< C <<" for VF " <<
+ VF << " For instruction: "<< *it << "\n");
+ }
+
+ // TODO: if-converted blocks can have a high-nest level. We need to
+ // calculate the loop nest level and multiply the cost accordingly.
+ if (Legal->blockNeedsPredication(*bb))
+ BlockCost *= 2;
+
+ Cost += BlockCost;
}
return Cost;
@@ -2106,6 +2116,7 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) {
return VTTI->getCFInstrCost(I->getOpcode());
}
case Instruction::PHI:
+ //TODO: IF-converted IFs become selects.
return 0;
case Instruction::Add:
case Instruction::FAdd: