[llvm] r268632 - [LV] Refactor the validation of PHI inductions. NFC
Silviu Baranga via llvm-commits
llvm-commits at lists.llvm.org
Thu May 5 08:14:01 PDT 2016
Author: sbaranga
Date: Thu May 5 10:14:01 2016
New Revision: 268632
URL: http://llvm.org/viewvc/llvm-project?rev=268632&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=268632&r1=268631&r2=268632&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Thu May 5 10:14:01 2016
@@ -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 Loo
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::canVecto
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;
}
More information about the llvm-commits
mailing list