diff options
| author | Silviu Baranga <silviu.baranga@arm.com> | 2016-05-05 15:14:01 +0000 |
|---|---|---|
| committer | Silviu Baranga <silviu.baranga@arm.com> | 2016-05-05 15:14:01 +0000 |
| commit | 7e0d4353f2b7a0d5e9071fe16121e2cda92e42d1 (patch) | |
| tree | 4de1da65a6324b4b566fcebf006c5d4646421290 /llvm/lib/Transforms | |
| parent | 0c145c0c3aece99865a759b71fe5fbb913d7ce70 (diff) | |
| download | bcm5719-llvm-7e0d4353f2b7a0d5e9071fe16121e2cda92e42d1.tar.gz bcm5719-llvm-7e0d4353f2b7a0d5e9071fe16121e2cda92e42d1.zip | |
[LV] Refactor the validation of PHI inductions. NFC
This moves the validation of PHI inductions into a
separate method, making it easier to reuse this
logic.
llvm-svn: 268632
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 77 |
1 files changed, 48 insertions, 29 deletions
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 981324a01e5..22f52a3986a 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1406,6 +1406,14 @@ private: /// invariant. void collectStridedAccess(Value *LoadOrStoreInst); + /// \brief Returns true if we can vectorize using this PHI node as an + /// induction. + /// + /// Updates the vectorization state by adding \p Phi to the inductions list. + /// This can set \p Phi as the main induction of the loop if \p Phi is a + /// better choice for the main induction than the existing one. + bool addInductionPhi(PHINode *Phi, InductionDescriptor ID); + /// Report an analysis message to assist the user in diagnosing loops that are /// not vectorized. These are handled as LoopAccessReport rather than /// VectorizationReport because the << operator of VectorizationReport returns @@ -4575,6 +4583,45 @@ static bool hasOutsideLoopUser(const Loop *TheLoop, Instruction *Inst, return false; } +bool LoopVectorizationLegality::addInductionPhi(PHINode *Phi, + InductionDescriptor ID) { + Inductions[Phi] = ID; + Type *PhiTy = Phi->getType(); + const DataLayout &DL = Phi->getModule()->getDataLayout(); + + // Get the widest type. + if (!WidestIndTy) + WidestIndTy = convertPointerToIntegerType(DL, PhiTy); + else + WidestIndTy = getWiderType(DL, PhiTy, WidestIndTy); + + // Int inductions are special because we only allow one IV. + if (ID.getKind() == InductionDescriptor::IK_IntInduction && + ID.getStepValue()->isOne() && + isa<Constant>(ID.getStartValue()) && + cast<Constant>(ID.getStartValue())->isNullValue()) { + // Use the phi node with the widest type as induction. Use the last + // one if there are multiple (no good reason for doing this other + // than it is expedient). We've checked that it begins at zero and + // steps by one, so this is a canonical induction variable. + if (!Induction || PhiTy == WidestIndTy) + Induction = Phi; + } + + DEBUG(dbgs() << "LV: Found an induction variable.\n"); + + // Until we explicitly handle the case of an induction variable with + // an outside loop user we have to give up vectorizing this loop. + if (hasOutsideLoopUser(TheLoop, Phi, AllowedExit)) { + emitAnalysis(VectorizationReport(Phi) << + "use of induction value outside of the " + "loop is not handled by vectorizer"); + return false; + } + + return true; +} + bool LoopVectorizationLegality::canVectorizeInstrs() { BasicBlock *Header = TheLoop->getHeader(); @@ -4628,36 +4675,8 @@ bool LoopVectorizationLegality::canVectorizeInstrs() { InductionDescriptor ID; if (InductionDescriptor::isInductionPHI(Phi, PSE.getSE(), ID)) { - Inductions[Phi] = ID; - // Get the widest type. - if (!WidestIndTy) - WidestIndTy = convertPointerToIntegerType(DL, PhiTy); - else - WidestIndTy = getWiderType(DL, PhiTy, WidestIndTy); - - // Int inductions are special because we only allow one IV. - if (ID.getKind() == InductionDescriptor::IK_IntInduction && - ID.getStepValue()->isOne() && isa<Constant>(ID.getStartValue()) && - cast<Constant>(ID.getStartValue())->isNullValue()) { - // Use the phi node with the widest type as induction. Use the last - // one if there are multiple (no good reason for doing this other - // than it is expedient). We've checked that it begins at zero and - // steps by one, so this is a canonical induction variable. - if (!Induction || PhiTy == WidestIndTy) - Induction = Phi; - } - - DEBUG(dbgs() << "LV: Found an induction variable.\n"); - - // Until we explicitly handle the case of an induction variable with - // an outside loop user we have to give up vectorizing this loop. - if (hasOutsideLoopUser(TheLoop, &*it, AllowedExit)) { - emitAnalysis(VectorizationReport(&*it) - << "use of induction value outside of the " - "loop is not handled by vectorizer"); + if (!addInductionPhi(Phi, ID)) return false; - } - continue; } |

