diff options
author | Philip Reames <listmail@philipreames.com> | 2019-07-03 20:03:46 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2019-07-03 20:03:46 +0000 |
commit | ea06d63c35645e149d601a34bdad0b43c4522d0f (patch) | |
tree | 9f7a9084eabb3b90b50fc9c91cface6604ee0b12 /llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | |
parent | f1807a7df6b31f4b774bfc6ad207fee5d8d32b99 (diff) | |
download | bcm5719-llvm-ea06d63c35645e149d601a34bdad0b43c4522d0f.tar.gz bcm5719-llvm-ea06d63c35645e149d601a34bdad0b43c4522d0f.zip |
[LFTR] Use SCEVExpander for the pointer limit case instead of manual IR gen
As noted in the test change, this is not trivially NFC, but all of the changes in output are cases where the SCEVExpander form is more canonical/optimal than the hand generation.
llvm-svn: 365075
Diffstat (limited to 'llvm/lib/Transforms/Scalar/IndVarSimplify.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index 84a94027b0a..1031916797e 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -2329,21 +2329,17 @@ static Value *genLoopLimit(PHINode *IndVar, BasicBlock *ExitingBB, // Expand the code for the iteration count. assert(SE->isLoopInvariant(IVOffset, L) && "Computed iteration count is not loop invariant!"); - BranchInst *BI = cast<BranchInst>(ExitingBB->getTerminator()); - Value *GEPOffset = Rewriter.expandCodeFor(IVOffset, OfsTy, BI); - Value *GEPBase = IndVar->getIncomingValueForBlock(L->getLoopPreheader()); - assert(AR->getStart() == SE->getSCEV(GEPBase) && "bad loop counter"); // We could handle pointer IVs other than i8*, but we need to compensate for // gep index scaling. assert(SE->getSizeOfExpr(IntegerType::getInt64Ty(IndVar->getContext()), - cast<PointerType>(GEPBase->getType()) + cast<PointerType>(IndVar->getType()) ->getElementType())->isOne() && "unit stride pointer IV must be i8*"); - IRBuilder<> Builder(L->getLoopPreheader()->getTerminator()); - return Builder.CreateGEP(GEPBase->getType()->getPointerElementType(), - GEPBase, GEPOffset, "lftr.limit"); + const SCEV *IVLimit = SE->getAddExpr(IVInit, IVOffset); + BranchInst *BI = cast<BranchInst>(ExitingBB->getTerminator()); + return Rewriter.expandCodeFor(IVLimit, IndVar->getType(), BI); } else { // In any other case, convert both IVInit and ExitCount to integers before // comparing. This may result in SCEV expansion of pointers, but in practice @@ -2379,8 +2375,6 @@ static Value *genLoopLimit(PHINode *IndVar, BasicBlock *ExitingBB, IVLimit = SE->getAddExpr(IVLimit, SE->getOne(IVLimit->getType())); // Expand the code for the iteration count. - BranchInst *BI = cast<BranchInst>(ExitingBB->getTerminator()); - IRBuilder<> Builder(BI); assert(SE->isLoopInvariant(IVLimit, L) && "Computed iteration count is not loop invariant!"); // Ensure that we generate the same type as IndVar, or a smaller integer @@ -2388,6 +2382,7 @@ static Value *genLoopLimit(PHINode *IndVar, BasicBlock *ExitingBB, // SCEV expression (IVInit) for a pointer type IV value (IndVar). Type *LimitTy = ExitCount->getType()->isPointerTy() ? IndVar->getType() : ExitCount->getType(); + BranchInst *BI = cast<BranchInst>(ExitingBB->getTerminator()); return Rewriter.expandCodeFor(IVLimit, LimitTy, BI); } } |