From 515acd64fd100322c92691971674399155132dfe Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Fri, 2 Mar 2018 12:24:25 +0000 Subject: [LV][CFG] Add irreducible CFG detection for outer loops This patch adds support for detecting outer loops with irreducible control flow in LV. Current detection uses SCCs and only works for innermost loops. This patch adds a utility function that works on any CFG, given its RPO traversal and its LoopInfoBase. This function is a generalization of isIrreducibleCFG from lib/CodeGen/ShrinkWrap.cpp. The code in lib/CodeGen/ShrinkWrap.cpp is also updated to use the new generic utility function. Patch by Diego Caballero Differential Revision: https://reviews.llvm.org/D40874 llvm-svn: 326568 --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 31 +++++++------------------ 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'llvm/lib/Transforms/Vectorize') diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 47a767ccbbe..d8d21dfcb85 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -56,7 +56,6 @@ #include "llvm/ADT/MapVector.h" #include "llvm/ADT/None.h" #include "llvm/ADT/Optional.h" -#include "llvm/ADT/SCCIterator.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallPtrSet.h" @@ -69,6 +68,7 @@ #include "llvm/Analysis/AssumptionCache.h" #include "llvm/Analysis/BasicAliasAnalysis.h" #include "llvm/Analysis/BlockFrequencyInfo.h" +#include "llvm/Analysis/CFG.h" #include "llvm/Analysis/CodeMetrics.h" #include "llvm/Analysis/DemandedBits.h" #include "llvm/Analysis/GlobalsModRef.h" @@ -283,24 +283,6 @@ class LoopVectorizationRequirements; } // end anonymous namespace -/// Returns true if the given loop body has a cycle, excluding the loop -/// itself. -static bool hasCyclesInLoopBody(const Loop &L) { - if (!L.empty()) - return true; - - for (const auto &SCC : - make_range(scc_iterator::begin(L), - scc_iterator::end(L))) { - if (SCC.size() > 1) { - DEBUG(dbgs() << "LVL: Detected a cycle in the loop body:\n"); - DEBUG(L.dump()); - return true; - } - } - return false; -} - /// A helper function for converting Scalar types to vector types. /// If the incoming type is void, we return void. If the VF is 1, we return /// the scalar type. @@ -2302,14 +2284,17 @@ private: } // end anonymous namespace -static void addAcyclicInnerLoop(Loop &L, SmallVectorImpl &V) { +static void addAcyclicInnerLoop(Loop &L, LoopInfo &LI, + SmallVectorImpl &V) { if (L.empty()) { - if (!hasCyclesInLoopBody(L)) + LoopBlocksRPO RPOT(&L); + RPOT.perform(&LI); + if (!containsIrreducibleCFG(RPOT, LI)) V.push_back(&L); return; } for (Loop *InnerL : L) - addAcyclicInnerLoop(*InnerL, V); + addAcyclicInnerLoop(*InnerL, LI, V); } namespace { @@ -8637,7 +8622,7 @@ bool LoopVectorizePass::runImpl( SmallVector Worklist; for (Loop *L : *LI) - addAcyclicInnerLoop(*L, Worklist); + addAcyclicInnerLoop(*L, *LI, Worklist); LoopsAnalyzed += Worklist.size(); -- cgit v1.2.3