[polly] r222096 - Introduce minimalistic cost model for auto parallelization

Tobias Grosser tobias at grosser.es
Sun Nov 16 06:24:54 PST 2014


Author: grosser
Date: Sun Nov 16 08:24:53 2014
New Revision: 222096

URL: http://llvm.org/viewvc/llvm-project?rev=222096&view=rev
Log:
Introduce minimalistic cost model for auto parallelization

Instead of parallelizing every parallel outermost loop, we now use a very
minimalistic cost model. Specifically, we assume innermost loops are not
worth parallelising and all non-innermost loops are.

When parallelizing all loops in LNT we got several slowdowns/timeouts due to
us parallelizing innermost loops that are executed only a couple of times
(number of iterations not known statically). With this basic heuristic enabled
LNT does not show any more timeouts, while several interesting loops are still
parallelized.

There are many ways to obtain an improved heuristic. Constructing such an
improvide heuristic from a position of minimal slow-down and zero code size
increase seems to be the best, as it allows us to track progress on LNT.

Modified:
    polly/trunk/lib/CodeGen/IslAst.cpp
    polly/trunk/test/Isl/Ast/OpenMP/multiple_loops_outer_parallel.ll
    polly/trunk/test/Isl/Ast/OpenMP/nested_loop_both_parallel_parametric.ll
    polly/trunk/test/Isl/Ast/OpenMP/nested_loop_inner_parallel.ll
    polly/trunk/test/Isl/Ast/OpenMP/single_loop_param_parallel.ll
    polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-iv.ll
    polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-values-2.ll
    polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-values-3.ll
    polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-values.ll
    polly/trunk/test/Isl/CodeGen/OpenMP/reference-other-bb.ll
    polly/trunk/test/Isl/CodeGen/OpenMP/reference-preceeding-loop.ll
    polly/trunk/test/Isl/CodeGen/OpenMP/single_loop.ll
    polly/trunk/test/Isl/CodeGen/OpenMP/single_loop_with_loop_invariant_baseptr.ll
    polly/trunk/test/Isl/CodeGen/OpenMP/two-parallel-loops-reference-outer-indvar.ll

Modified: polly/trunk/lib/CodeGen/IslAst.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslAst.cpp?rev=222096&r1=222095&r2=222096&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslAst.cpp (original)
+++ polly/trunk/lib/CodeGen/IslAst.cpp Sun Nov 16 08:24:53 2014
@@ -47,6 +47,11 @@ static cl::opt<bool>
                   cl::desc("Generate thread parallel code (isl codegen only)"),
                   cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
 
+static cl::opt<bool> PollyParallelForce(
+    "polly-parallel-force",
+    cl::desc("Force generation of thread parallel code ignoring any cost model"),
+    cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
+
 static cl::opt<bool> UseContext("polly-ast-use-context",
                                 cl::desc("Use context"), cl::Hidden,
                                 cl::init(false), cl::ZeroOrMore,
@@ -454,8 +459,23 @@ bool IslAstInfo::isReductionParallel(__i
 }
 
 bool IslAstInfo::isExecutedInParallel(__isl_keep isl_ast_node *Node) {
-  return PollyParallel && isOutermostParallel(Node) &&
-         !isReductionParallel(Node);
+
+  if (!PollyParallel)
+    return false;
+
+  // Do not parallelize innermost loops.
+  //
+  // Parallelizing innermost loops is often not profitable, especially if
+  // they have a low number of iterations.
+  //
+  // TODO: Decide this based on the number of loop iterations that will be
+  //       executed. This can possibly require run-time checks, which again
+  //       raises the question of both run-time check overhead and code size
+  //       costs.
+  if (!PollyParallelForce && isInnermost(Node))
+    return false;
+
+  return isOutermostParallel(Node) && !isReductionParallel(Node);
 }
 
 isl_union_map *IslAstInfo::getSchedule(__isl_keep isl_ast_node *Node) {

Modified: polly/trunk/test/Isl/Ast/OpenMP/multiple_loops_outer_parallel.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/Ast/OpenMP/multiple_loops_outer_parallel.ll?rev=222096&r1=222095&r2=222096&view=diff
==============================================================================
--- polly/trunk/test/Isl/Ast/OpenMP/multiple_loops_outer_parallel.ll (original)
+++ polly/trunk/test/Isl/Ast/OpenMP/multiple_loops_outer_parallel.ll Sun Nov 16 08:24:53 2014
@@ -1,4 +1,4 @@
-; RUN: opt %loadPolly -polly-ast -polly-parallel -analyze < %s | FileCheck %s
+; RUN: opt %loadPolly -polly-ast -polly-parallel -polly-parallel-force -analyze < %s | FileCheck %s
 ;
 ;       void jd(int *A) {
 ; CHECK:  #pragma omp parallel for

Modified: polly/trunk/test/Isl/Ast/OpenMP/nested_loop_both_parallel_parametric.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/Ast/OpenMP/nested_loop_both_parallel_parametric.ll?rev=222096&r1=222095&r2=222096&view=diff
==============================================================================
--- polly/trunk/test/Isl/Ast/OpenMP/nested_loop_both_parallel_parametric.ll (original)
+++ polly/trunk/test/Isl/Ast/OpenMP/nested_loop_both_parallel_parametric.ll Sun Nov 16 08:24:53 2014
@@ -1,4 +1,4 @@
-; RUN: opt %loadPolly -polly-ast -polly-parallel -analyze -polly-delinearize < %s | FileCheck %s
+; RUN: opt %loadPolly -polly-ast -polly-parallel -polly-parallel-force -analyze -polly-delinearize < %s | FileCheck %s
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 target triple = "x86_64-pc-linux-gnu"
 ; int A[1024][1024];

Modified: polly/trunk/test/Isl/Ast/OpenMP/nested_loop_inner_parallel.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/Ast/OpenMP/nested_loop_inner_parallel.ll?rev=222096&r1=222095&r2=222096&view=diff
==============================================================================
--- polly/trunk/test/Isl/Ast/OpenMP/nested_loop_inner_parallel.ll (original)
+++ polly/trunk/test/Isl/Ast/OpenMP/nested_loop_inner_parallel.ll Sun Nov 16 08:24:53 2014
@@ -1,4 +1,4 @@
-; RUN: opt %loadPolly -polly-ast -polly-parallel -analyze < %s | FileCheck %s
+; RUN: opt %loadPolly -polly-ast -polly-parallel -polly-parallel-force -analyze < %s | FileCheck %s
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 target triple = "x86_64-pc-linux-gnu"
 

Modified: polly/trunk/test/Isl/Ast/OpenMP/single_loop_param_parallel.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/Ast/OpenMP/single_loop_param_parallel.ll?rev=222096&r1=222095&r2=222096&view=diff
==============================================================================
--- polly/trunk/test/Isl/Ast/OpenMP/single_loop_param_parallel.ll (original)
+++ polly/trunk/test/Isl/Ast/OpenMP/single_loop_param_parallel.ll Sun Nov 16 08:24:53 2014
@@ -1,4 +1,4 @@
-; RUN: opt %loadPolly -polly-ast -polly-parallel -analyze < %s | FileCheck %s
+; RUN: opt %loadPolly -polly-ast -polly-parallel -polly-parallel-force -analyze < %s | FileCheck %s
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 target triple = "x86_64-pc-linux-gnu"
 

Modified: polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-iv.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-iv.ll?rev=222096&r1=222095&r2=222096&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-iv.ll (original)
+++ polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-iv.ll Sun Nov 16 08:24:53 2014
@@ -1,5 +1,5 @@
-; RUN: opt %loadPolly -polly-parallel -polly-ast -analyze < %s | FileCheck %s -check-prefix=AST
-; RUN: opt %loadPolly -polly-parallel -polly-codegen-isl -S -polly-codegen-scev -verify-dom-info < %s | FileCheck %s -check-prefix=IR
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-ast -analyze < %s | FileCheck %s -check-prefix=AST
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-codegen-isl -S -polly-codegen-scev -verify-dom-info < %s | FileCheck %s -check-prefix=IR
 
 ; This code has failed the scev based code generation as the scev in the scop
 ; contains an AddRecExpr of an outer loop. When generating code, we did not

Modified: polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-values-2.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-values-2.ll?rev=222096&r1=222095&r2=222096&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-values-2.ll (original)
+++ polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-values-2.ll Sun Nov 16 08:24:53 2014
@@ -1,6 +1,6 @@
-; RUN: opt %loadPolly -polly-parallel -polly-ast -analyze < %s | FileCheck %s -check-prefix=AST
-; RUN: opt %loadPolly -polly-parallel -polly-codegen-isl -S -verify-dom-info < %s | FileCheck %s -check-prefix=IR
-; RUN: opt %loadPolly -polly-parallel -polly-codegen-isl -S -polly-codegen-scev -verify-dom-info < %s | FileCheck %s -check-prefix=IR-SCEV
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-ast -analyze < %s | FileCheck %s -check-prefix=AST
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-codegen-isl -S -verify-dom-info < %s | FileCheck %s -check-prefix=IR
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-codegen-isl -S -polly-codegen-scev -verify-dom-info < %s | FileCheck %s -check-prefix=IR-SCEV
 
 ; AST: #pragma simd
 ; AST: #pragma omp parallel for

Modified: polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-values-3.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-values-3.ll?rev=222096&r1=222095&r2=222096&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-values-3.ll (original)
+++ polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-values-3.ll Sun Nov 16 08:24:53 2014
@@ -1,6 +1,6 @@
-; RUN: opt %loadPolly -basicaa -polly-parallel -polly-ast -analyze < %s | FileCheck %s -check-prefix=AST
-; RUN: opt %loadPolly -basicaa -polly-parallel -polly-codegen-isl -S -verify-dom-info < %s | FileCheck %s -check-prefix=IR
-; RUN: opt %loadPolly -basicaa -polly-parallel -polly-codegen-isl -S -polly-codegen-scev -verify-dom-info < %s | FileCheck %s -check-prefix=IR
+; RUN: opt %loadPolly -basicaa -polly-parallel -polly-parallel-force -polly-ast -analyze < %s | FileCheck %s -check-prefix=AST
+; RUN: opt %loadPolly -basicaa -polly-parallel -polly-parallel-force -polly-codegen-isl -S -verify-dom-info < %s | FileCheck %s -check-prefix=IR
+; RUN: opt %loadPolly -basicaa -polly-parallel -polly-parallel-force -polly-codegen-isl -S -polly-codegen-scev -verify-dom-info < %s | FileCheck %s -check-prefix=IR
 
 ; The interesting part of this test case is the instruction:
 ;   %tmp = bitcast i8* %call to i64**

Modified: polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-values.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-values.ll?rev=222096&r1=222095&r2=222096&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-values.ll (original)
+++ polly/trunk/test/Isl/CodeGen/OpenMP/loop-body-references-outer-values.ll Sun Nov 16 08:24:53 2014
@@ -1,6 +1,6 @@
-; RUN: opt %loadPolly -polly-parallel -polly-ast -analyze < %s | FileCheck %s -check-prefix=AST
-; RUN: opt %loadPolly -polly-parallel -polly-codegen-isl -S < %s | FileCheck %s -check-prefix=IR
-; RUN: opt %loadPolly -polly-parallel -polly-codegen-isl -S -polly-codegen-scev < %s | FileCheck %s -check-prefix=IR
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-ast -analyze < %s | FileCheck %s -check-prefix=AST
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-codegen-isl -S < %s | FileCheck %s -check-prefix=IR
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-codegen-isl -S -polly-codegen-scev < %s | FileCheck %s -check-prefix=IR
 
 ; Make sure we correctly forward the reference to 'A' to the OpenMP subfunction.
 ;

Modified: polly/trunk/test/Isl/CodeGen/OpenMP/reference-other-bb.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/OpenMP/reference-other-bb.ll?rev=222096&r1=222095&r2=222096&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/OpenMP/reference-other-bb.ll (original)
+++ polly/trunk/test/Isl/CodeGen/OpenMP/reference-other-bb.ll Sun Nov 16 08:24:53 2014
@@ -1,4 +1,4 @@
-; RUN: opt %loadPolly -polly-parallel -polly-codegen-isl -S -polly-codegen-scev -verify-dom-info < %s | FileCheck %s -check-prefix=IR
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-codegen-isl -S -polly-codegen-scev -verify-dom-info < %s | FileCheck %s -check-prefix=IR
 
 ; IR: @foo.polly.subfn
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"

Modified: polly/trunk/test/Isl/CodeGen/OpenMP/reference-preceeding-loop.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/OpenMP/reference-preceeding-loop.ll?rev=222096&r1=222095&r2=222096&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/OpenMP/reference-preceeding-loop.ll (original)
+++ polly/trunk/test/Isl/CodeGen/OpenMP/reference-preceeding-loop.ll Sun Nov 16 08:24:53 2014
@@ -1,5 +1,5 @@
-; RUN: opt %loadPolly -polly-parallel -polly-ast -analyze -polly-codegen-scev < %s | FileCheck %s -check-prefix=AST
-; RUN: opt %loadPolly -polly-parallel -polly-codegen-isl -S -polly-codegen-scev -verify-dom-info < %s | FileCheck %s -check-prefix=IR
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-ast -analyze -polly-codegen-scev < %s | FileCheck %s -check-prefix=AST
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-codegen-isl -S -polly-codegen-scev -verify-dom-info < %s | FileCheck %s -check-prefix=IR
 
 
 ; - Test the case where scalar evolution references a loop that is outside

Modified: polly/trunk/test/Isl/CodeGen/OpenMP/single_loop.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/OpenMP/single_loop.ll?rev=222096&r1=222095&r2=222096&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/OpenMP/single_loop.ll (original)
+++ polly/trunk/test/Isl/CodeGen/OpenMP/single_loop.ll Sun Nov 16 08:24:53 2014
@@ -1,10 +1,10 @@
-; RUN: opt %loadPolly -polly-parallel -polly-ast -analyze < %s | FileCheck %s -check-prefix=AST
-; RUN: opt %loadPolly -polly-parallel -polly-codegen-isl -S -verify-dom-info < %s | FileCheck %s -check-prefix=IR
-; RUN: opt %loadPolly -polly-parallel -polly-codegen-isl -S -polly-codegen-scev -verify-dom-info < %s | FileCheck %s -check-prefix=IR
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-ast -analyze < %s | FileCheck %s -check-prefix=AST
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-codegen-isl -S -verify-dom-info < %s | FileCheck %s -check-prefix=IR
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-codegen-isl -S -polly-codegen-scev -verify-dom-info < %s | FileCheck %s -check-prefix=IR
 
-; RUN: opt %loadPolly -polly-parallel -polly-import-jscop -polly-import-jscop-dir=%S -polly-ast -analyze < %s | FileCheck %s -check-prefix=AST-STRIDE4
-; RUN: opt %loadPolly -polly-parallel -polly-import-jscop -polly-import-jscop-dir=%S -polly-codegen-isl -S < %s | FileCheck %s -check-prefix=IR-STRIDE4
-; RUN: opt %loadPolly -polly-parallel -polly-import-jscop -polly-import-jscop-dir=%S -polly-codegen-isl -polly-codegen-scev -S < %s | FileCheck %s -check-prefix=IR-STRIDE4
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-import-jscop -polly-import-jscop-dir=%S -polly-ast -analyze < %s | FileCheck %s -check-prefix=AST-STRIDE4
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-import-jscop -polly-import-jscop-dir=%S -polly-codegen-isl -S < %s | FileCheck %s -check-prefix=IR-STRIDE4
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-import-jscop -polly-import-jscop-dir=%S -polly-codegen-isl -polly-codegen-scev -S < %s | FileCheck %s -check-prefix=IR-STRIDE4
 
 ; This extensive test case tests the creation of the full set of OpenMP calls
 ; as well as the subfunction creation using a trivial loop as example.

Modified: polly/trunk/test/Isl/CodeGen/OpenMP/single_loop_with_loop_invariant_baseptr.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/OpenMP/single_loop_with_loop_invariant_baseptr.ll?rev=222096&r1=222095&r2=222096&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/OpenMP/single_loop_with_loop_invariant_baseptr.ll (original)
+++ polly/trunk/test/Isl/CodeGen/OpenMP/single_loop_with_loop_invariant_baseptr.ll Sun Nov 16 08:24:53 2014
@@ -1,6 +1,6 @@
-; RUN: opt %loadPolly -tbaa -polly-parallel -polly-ast -analyze < %s | FileCheck %s -check-prefix=AST
-; RUN: opt %loadPolly -tbaa -polly-parallel -polly-codegen-isl -S -verify-dom-info < %s | FileCheck %s -check-prefix=IR
-; RUN: opt %loadPolly -tbaa -polly-parallel -polly-codegen-isl -S -polly-codegen-scev -verify-dom-info < %s | FileCheck %s -check-prefix=IR
+; RUN: opt %loadPolly -tbaa -polly-parallel -polly-parallel-force -polly-parallel-force -polly-ast -analyze < %s | FileCheck %s -check-prefix=AST
+; RUN: opt %loadPolly -tbaa -polly-parallel -polly-parallel-force -polly-parallel-force -polly-codegen-isl -S -verify-dom-info < %s | FileCheck %s -check-prefix=IR
+; RUN: opt %loadPolly -tbaa -polly-parallel -polly-parallel-force -polly-parallel-force -polly-codegen-isl -S -polly-codegen-scev -verify-dom-info < %s | FileCheck %s -check-prefix=IR
 
 ; #define N 1024
 ; float A[N];

Modified: polly/trunk/test/Isl/CodeGen/OpenMP/two-parallel-loops-reference-outer-indvar.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/OpenMP/two-parallel-loops-reference-outer-indvar.ll?rev=222096&r1=222095&r2=222096&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/OpenMP/two-parallel-loops-reference-outer-indvar.ll (original)
+++ polly/trunk/test/Isl/CodeGen/OpenMP/two-parallel-loops-reference-outer-indvar.ll Sun Nov 16 08:24:53 2014
@@ -1,5 +1,5 @@
-; RUN: opt %loadPolly -polly-parallel -polly-ast -analyze -polly-codegen-scev < %s | FileCheck %s -check-prefix=AST
-; RUN: opt %loadPolly -polly-parallel -polly-codegen-isl -S -polly-codegen-scev -verify-dom-info < %s | FileCheck %s -check-prefix=IR
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-ast -analyze -polly-codegen-scev < %s | FileCheck %s -check-prefix=AST
+; RUN: opt %loadPolly -polly-parallel -polly-parallel-force -polly-codegen-isl -S -polly-codegen-scev -verify-dom-info < %s | FileCheck %s -check-prefix=IR
 
 ; This test case verifies that we create correct code even if two OpenMP loops
 ; share common outer variables.





More information about the llvm-commits mailing list