[polly] r269064 - Weaken profitability constraints during ScopDetection

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Tue May 10 07:42:31 PDT 2016


Author: jdoerfert
Date: Tue May 10 09:42:30 2016
New Revision: 269064

URL: http://llvm.org/viewvc/llvm-project?rev=269064&view=rev
Log:
Weaken profitability constraints during ScopDetection

  Regions with one affine loop can be profitable if the loop is
  distributable. To this end we will allow them to be treated as
  profitable if they contain at least two non-trivial basic blocks.


Modified:
    polly/trunk/include/polly/ScopDetection.h
    polly/trunk/lib/Analysis/ScopDetection.cpp
    polly/trunk/test/ScopDetect/only-one-affine-loop.ll
    polly/trunk/test/ScopInfo/NonAffine/non_affine_loop_used_later.ll

Modified: polly/trunk/include/polly/ScopDetection.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopDetection.h?rev=269064&r1=269063&r2=269064&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopDetection.h (original)
+++ polly/trunk/include/polly/ScopDetection.h Tue May 10 09:42:30 2016
@@ -318,6 +318,17 @@ private:
   bool hasSufficientCompute(DetectionContext &Context,
                             int NumAffineLoops) const;
 
+  /// @brief Check if the unique affine loop might be amendable to distribution.
+  ///
+  /// This function checks if the number of non-trivial blocks in the unique
+  /// affine loop in Context.CurRegion is at least two, thus if the loop might
+  /// be amendable to distribution.
+  ///
+  /// @param Context  The context of scop detection.
+  ///
+  /// @return True only if the affine loop might be amendable to distributable.
+  bool hasPossiblyDistributableLoop(DetectionContext &Context) const;
+
   /// @brief Check if a region is profitable to optimize.
   ///
   /// Regions that are unlikely to expose interesting optimization opportunities

Modified: polly/trunk/lib/Analysis/ScopDetection.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopDetection.cpp?rev=269064&r1=269063&r2=269064&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopDetection.cpp (original)
+++ polly/trunk/lib/Analysis/ScopDetection.cpp Tue May 10 09:42:30 2016
@@ -1269,6 +1269,26 @@ bool ScopDetection::hasSufficientCompute
   return InstCount >= ProfitabilityMinPerLoopInstructions;
 }
 
+bool ScopDetection::hasPossiblyDistributableLoop(
+    DetectionContext &Context) const {
+  for (auto *BB : Context.CurRegion.blocks()) {
+    auto *L = LI->getLoopFor(BB);
+    if (!Context.CurRegion.contains(L))
+      continue;
+    if (Context.BoxedLoopsSet.count(L))
+      continue;
+    unsigned StmtsWithStoresInLoops = 0;
+    for (auto *LBB : L->blocks()) {
+      bool MemStore = false;
+      for (auto &I : *LBB)
+        MemStore |= isa<StoreInst>(&I);
+      StmtsWithStoresInLoops += MemStore;
+    }
+    return (StmtsWithStoresInLoops > 1);
+  }
+  return false;
+}
+
 bool ScopDetection::isProfitableRegion(DetectionContext &Context) const {
   Region &CurRegion = Context.CurRegion;
 
@@ -1288,6 +1308,10 @@ bool ScopDetection::isProfitableRegion(D
   if (NumAffineLoops >= 2)
     return true;
 
+  // A loop with multiple non-trivial blocks migt be amendable to distribution.
+  if (NumAffineLoops == 1 && hasPossiblyDistributableLoop(Context))
+    return true;
+
   // Scops that contain a loop with a non-trivial amount of computation per
   // loop-iteration are interesting as we may be able to parallelize such
   // loops. Individual loops that have only a small amount of computation

Modified: polly/trunk/test/ScopDetect/only-one-affine-loop.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopDetect/only-one-affine-loop.ll?rev=269064&r1=269063&r2=269064&view=diff
==============================================================================
--- polly/trunk/test/ScopDetect/only-one-affine-loop.ll (original)
+++ polly/trunk/test/ScopDetect/only-one-affine-loop.ll Tue May 10 09:42:30 2016
@@ -1,14 +1,11 @@
 ; RUN: opt %loadPolly -polly-detect -polly-process-unprofitable=false -analyze \
 ; RUN:     -polly-allow-nonaffine-loops < %s | FileCheck %s
 ;
-; RUN: opt %loadPolly -polly-detect -analyze \
-; RUN:     -polly-allow-nonaffine-loops < %s | FileCheck %s --check-prefix=UNPROFIT
-;
 ; Even if we allow non-affine loops we can only model the outermost loop, all
-; other loops are boxed in non-affine regions
+; other loops are boxed in non-affine regions. However, the inner loops can be
+; distributed as black-boxes, thus we will recognize the outer loop as profitable.
 ;
-; CHECK-NOT: Valid
-; UNPROFIT:  Valid Region for Scop: for.cond => for.end.51
+; CHECK:  Valid Region for Scop: for.cond => for.end.51
 ;
 ;    void f(int *A) {
 ;      for (int i = 0; i < 100; i++) {

Modified: polly/trunk/test/ScopInfo/NonAffine/non_affine_loop_used_later.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/NonAffine/non_affine_loop_used_later.ll?rev=269064&r1=269063&r2=269064&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/NonAffine/non_affine_loop_used_later.ll (original)
+++ polly/trunk/test/ScopInfo/NonAffine/non_affine_loop_used_later.ll Tue May 10 09:42:30 2016
@@ -86,7 +86,9 @@
 ; CHECK-NEXT:             [N] -> { Stmt_bb23[i0] -> MemRef_j_0__phi[] };
 ; CHECK-NEXT: }
 ;
-; PROFIT-NOT: Statements
+; As we might be able to distribute the outer loop we consider the region profitable for now.
+;
+; PROFIT: Statements
 ;
 ;    void f(int *A, int N, int M) {
 ;      int i = 0, j = 0;




More information about the llvm-commits mailing list