diff options
author | Florian Hahn <florian.hahn@arm.com> | 2016-12-19 17:13:37 +0000 |
---|---|---|
committer | Florian Hahn <florian.hahn@arm.com> | 2016-12-19 17:13:37 +0000 |
commit | 2e03213f90b0c443a4f3415757e8893d70420a85 (patch) | |
tree | cee22297bbbc2d12448cce13934cf6c33b1ce644 /llvm/lib/Transforms | |
parent | 17cb7c0a2a40151960d5e105bd2b7d9772c97086 (diff) | |
download | bcm5719-llvm-2e03213f90b0c443a4f3415757e8893d70420a85.tar.gz bcm5719-llvm-2e03213f90b0c443a4f3415757e8893d70420a85.zip |
[LoopVersioning] Require loop-simplify form for loop versioning.
Summary:
Requiring loop-simplify form for loop versioning ensures that the
runtime check block always dominates the exit block.
This patch closes #30958 (https://llvm.org/bugs/show_bug.cgi?id=30958).
Reviewers: silviu.baranga, hfinkel, anemet, ashutosh.nema
Subscribers: ashutosh.nema, mzolotukhin, efriedma, hfinkel, llvm-commits
Differential Revision: https://reviews.llvm.org/D27469
llvm-svn: 290116
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopDistribute.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopVersioningLICM.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopVersioning.cpp | 6 |
4 files changed, 17 insertions, 14 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp index 1db8caa0a34..1da0fd8d2a8 100644 --- a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp +++ b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp @@ -606,11 +606,13 @@ public: DEBUG(dbgs() << "\nLDist: In \"" << L->getHeader()->getParent()->getName() << "\" checking " << *L << "\n"); - BasicBlock *PH = L->getLoopPreheader(); - if (!PH) - return fail("NoHeader", "no preheader"); if (!L->getExitBlock()) return fail("MultipleExitBlocks", "multiple exit blocks"); + if (!L->isLoopSimplifyForm()) + return fail("NotLoopSimplifyForm", + "loop is not in loop-simplify form"); + + BasicBlock *PH = L->getLoopPreheader(); // LAA will check that we only have a single exiting block. LAI = &GetLAA(*L); diff --git a/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp b/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp index 8e83c4700aa..08e7acdaaf7 100644 --- a/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp +++ b/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp @@ -517,6 +517,11 @@ public: return false; } + if (!L->isLoopSimplifyForm()) { + DEBUG(dbgs() << "Loop is not is loop-simplify form"); + return false; + } + // Point of no-return, start the transformation. First, version the loop // if necessary. diff --git a/llvm/lib/Transforms/Scalar/LoopVersioningLICM.cpp b/llvm/lib/Transforms/Scalar/LoopVersioningLICM.cpp index aa09f894310..c23d891b650 100644 --- a/llvm/lib/Transforms/Scalar/LoopVersioningLICM.cpp +++ b/llvm/lib/Transforms/Scalar/LoopVersioningLICM.cpp @@ -218,9 +218,10 @@ private: /// \brief Check loop structure and confirms it's good for LoopVersioningLICM. bool LoopVersioningLICM::legalLoopStructure() { - // Loop must have a preheader, if not return false. - if (!CurLoop->getLoopPreheader()) { - DEBUG(dbgs() << " loop preheader is missing\n"); + // Loop must be in loop simplify form. + if (!CurLoop->isLoopSimplifyForm()) { + DEBUG( + dbgs() << " loop is not in loop-simplify form.\n"); return false; } // Loop should be innermost loop, if not return false. @@ -256,11 +257,6 @@ bool LoopVersioningLICM::legalLoopStructure() { DEBUG(dbgs() << " loop depth is more then threshold\n"); return false; } - // Loop should have a dedicated exit block, if not return false. - if (!CurLoop->hasDedicatedExits()) { - DEBUG(dbgs() << " loop does not has dedicated exit blocks\n"); - return false; - } // We need to be able to compute the loop trip count in order // to generate the bound checks. const SCEV *ExitCount = SE->getBackedgeTakenCount(CurLoop); diff --git a/llvm/lib/Transforms/Utils/LoopVersioning.cpp b/llvm/lib/Transforms/Utils/LoopVersioning.cpp index b3c61691da3..29756d9dab7 100644 --- a/llvm/lib/Transforms/Utils/LoopVersioning.cpp +++ b/llvm/lib/Transforms/Utils/LoopVersioning.cpp @@ -36,7 +36,7 @@ LoopVersioning::LoopVersioning(const LoopAccessInfo &LAI, Loop *L, LoopInfo *LI, : VersionedLoop(L), NonVersionedLoop(nullptr), LAI(LAI), LI(LI), DT(DT), SE(SE) { assert(L->getExitBlock() && "No single exit block"); - assert(L->getLoopPreheader() && "No preheader"); + assert(L->isLoopSimplifyForm() && "Loop is not in loop-simplify form"); if (UseLAIChecks) { setAliasChecks(LAI.getRuntimePointerChecking()->getChecks()); setSCEVChecks(LAI.getPSE().getUnionPredicate()); @@ -278,8 +278,8 @@ public: bool Changed = false; for (Loop *L : Worklist) { const LoopAccessInfo &LAI = LAA->getInfo(L); - if (LAI.getNumRuntimePointerChecks() || - !LAI.getPSE().getUnionPredicate().isAlwaysTrue()) { + if (L->isLoopSimplifyForm() && (LAI.getNumRuntimePointerChecks() || + !LAI.getPSE().getUnionPredicate().isAlwaysTrue())) { LoopVersioning LVer(LAI, L, LI, DT, SE); LVer.versionLoop(); LVer.annotateLoopWithNoAlias(); |