summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNadav Rotem <nrotem@apple.com>2012-10-18 17:31:49 +0000
committerNadav Rotem <nrotem@apple.com>2012-10-18 17:31:49 +0000
commitbef36ac2a47dd647af332b8594031df6fe2522c5 (patch)
treec2262b9aa44f1a002df595086220ca60f57ff66f /lib
parentb1f8c139c5c1b1a50bf65b8141dd57434c793e54 (diff)
When looking for a vector representation of a scalar, do a single lookup. Also, cache the result of the broadcast instruction.
No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166191 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Vectorize/LoopVectorize.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp
index e3b8fc7be9f..cb671633e0d 100644
--- a/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -63,7 +63,6 @@ namespace {
/// to a given vectorization factor (VF).
class SingleBlockLoopVectorizer {
public:
-
/// Ctor.
SingleBlockLoopVectorizer(Loop *OrigLoop, ScalarEvolution *Se, LoopInfo *Li,
LPPassManager *Lpm, unsigned VecWidth):
@@ -118,6 +117,8 @@ private:
/// broadcast them into a vector.
Value *getVectorValue(Value *V);
+ typedef DenseMap<Value*, Value*> ValueMap;
+
/// The original loop.
Loop *Orig;
// Scev analysis to use.
@@ -139,7 +140,7 @@ private:
/// The induction variable of the old basic block.
PHINode *OldInduction;
// Maps scalars to widened vectors.
- DenseMap<Value*, Value*> WidenMap;
+ ValueMap WidenMap;
};
/// Perform the vectorization legality check. This class does not look at the
@@ -284,8 +285,8 @@ bool SingleBlockLoopVectorizer::isConsecutiveGep(GetElementPtrInst *Gep) {
if (!SE->isLoopInvariant(SE->getSCEV(Gep->getOperand(i)), Orig))
return false;
- // The last operand has to be the induction in order to emit
- // a wide load/store.
+ // We can emit wide load/stores only of the last index is the induction
+ // variable.
const SCEV *Last = SE->getSCEV(LastIndex);
if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(Last)) {
const SCEV *Step = AR->getStepRecurrence(*SE);
@@ -300,9 +301,15 @@ bool SingleBlockLoopVectorizer::isConsecutiveGep(GetElementPtrInst *Gep) {
}
Value *SingleBlockLoopVectorizer::getVectorValue(Value *V) {
- if (WidenMap.count(V))
- return WidenMap[V];
- return getBroadcastInstrs(V);
+ // If we saved a vectorized copy of V, use it.
+ ValueMap::iterator it = WidenMap.find(V);
+ if (it != WidenMap.end())
+ return it->second;
+
+ // Broadcast V and save the value for future uses.
+ Value *B = getBroadcastInstrs(V);
+ WidenMap[V] = B;
+ return B;
}
void SingleBlockLoopVectorizer::scalarizeInstruction(Instruction *Instr) {