diff options
author | James Molloy <james.molloy@arm.com> | 2015-09-02 10:14:54 +0000 |
---|---|---|
committer | James Molloy <james.molloy@arm.com> | 2015-09-02 10:14:54 +0000 |
commit | c07701b017cc729a268f28f1e50fae32d331b615 (patch) | |
tree | 34af1724d4ef5be610f9d58d8ae5537d56abadf6 /llvm/lib | |
parent | d4b21935cccbde173a28c052cbb56a4bc7cfae02 (diff) | |
download | bcm5719-llvm-c07701b017cc729a268f28f1e50fae32d331b615.tar.gz bcm5719-llvm-c07701b017cc729a268f28f1e50fae32d331b615.zip |
[LV] Switch to using canonical induction variables.
Vectorized loops only ever have one induction variable. All induction PHIs from the scalar loop are rewritten to be in terms of this single indvar.
We were trying very hard to pick an indvar that already existed, even if that indvar wasn't canonical (didn't start at zero). But trying so hard is really fruitless - creating a new, canonical, indvar only results in one extra add in the worst case and that add is trivially easy to push through the PHI out of the loop by instcombine.
If we try and be less clever here and instead let instcombine clean up our mess (as we do in many other places in LV), we can remove unneeded complexity.
llvm-svn: 246630
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index eaa3ecd48e4..70199ace35c 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2652,15 +2652,8 @@ void InnerLoopVectorizer::createEmptyLoop() { ConstantInt::get(ExitCountValue->getType(), VF * UF), "min.iters.check", VectorPH->getTerminator()); - // The loop index does not have to start at Zero. Find the original start - // value from the induction PHI node. If we don't have an induction variable - // then we know that it starts at zero. Builder.SetInsertPoint(VectorPH->getTerminator()); - Value *StartIdx = ExtendedIdx = - OldInduction - ? Builder.CreateZExt(OldInduction->getIncomingValueForBlock(VectorPH), - IdxTy) - : ConstantInt::get(IdxTy, 0); + Value *StartIdx = ExtendedIdx = ConstantInt::get(IdxTy, 0); // Count holds the overall loop count (N). Value *Count = Exp.expandCodeFor(ExitCount, ExitCount->getType(), @@ -3542,10 +3535,8 @@ void InnerLoopVectorizer::widenPHIInstruction(Instruction *PN, } else { // Handle other induction variables that are now based on the // canonical one. - Value *NormalizedIdx = Builder.CreateSub(Induction, ExtendedIdx, - "normalized.idx"); - NormalizedIdx = Builder.CreateSExtOrTrunc(NormalizedIdx, PhiTy); - Broadcasted = II.transform(Builder, NormalizedIdx); + auto *V = Builder.CreateSExtOrTrunc(Induction, PhiTy); + Broadcasted = II.transform(Builder, V); Broadcasted->setName("offset.idx"); } Broadcasted = getBroadcastInstrs(Broadcasted); @@ -4134,10 +4125,13 @@ bool LoopVectorizationLegality::canVectorizeInstrs() { // Int inductions are special because we only allow one IV. if (ID.getKind() == InductionDescriptor::IK_IntInduction && - ID.getStepValue()->isOne()) { + 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). + // 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; } |