Do not detect Scops with only one loop.
If a region does not have more than one loop, we do not identify it as
a Scop in ScopDetection. The main optimizations Polly is currently performing
(tiling, preparation for outer-loop vectorization and loop fusion) are unlikely
to have a positive impact on individual loops. In some cases, Polly's run-time
alias checks or conditional hoisting may still have a positive impact, but those
are mostly enabling transformations which LLVM already performs for individual
loops. As we do not focus on individual loops, we leave them untouched to not
introduce compile time regressions and execution time noise. This results in
good compile time reduction (oourafft: -73.99%, smg2000: -56.25%).
Contributed-by: Pratik Bhatu <cs12b1010@iith.ac.in>
Reviewers: grosser
Differential Revision: http://reviews.llvm.org/D12268
llvm-svn: 246161
diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp
index 17fc68c..58a8cc8 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -798,6 +798,23 @@
return invalid<ReportLoopBound>(Context, /*Assert=*/true, L, LoopCount);
}
+bool ScopDetection::hasMoreThanOneLoop(Region *R) const {
+ Loop *EntryLoop = LI->getLoopFor(R->getEntry());
+ if (!EntryLoop)
+ return false;
+
+ if (!EntryLoop->getSubLoops().empty())
+ return true;
+
+ for (pred_iterator PI = pred_begin(R->getExit()), PE = pred_end(R->getExit());
+ PI != PE; ++PI)
+ if (R->contains(*PI))
+ if (EntryLoop != LI->getLoopFor(*PI))
+ return true;
+
+ return false;
+}
+
Region *ScopDetection::expandRegion(Region &R) {
// Initial no valid region was found (greater than R)
std::unique_ptr<Region> LastValidRegion;
@@ -1009,6 +1026,9 @@
&(CurRegion.getEntry()->getParent()->getEntryBlock()))
return invalid<ReportEntry>(Context, /*Assert=*/true, CurRegion.getEntry());
+ if (!DetectUnprofitable && !hasMoreThanOneLoop(&CurRegion))
+ invalid<ReportUnprofitable>(Context, /*Assert=*/true, &CurRegion);
+
if (!isValidExit(Context))
return false;