[polly] r245540 - Check for feasible runtime check context early

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 19 22:58:56 PDT 2015


Author: jdoerfert
Date: Thu Aug 20 00:58:56 2015
New Revision: 245540

URL: http://llvm.org/viewvc/llvm-project?rev=245540&view=rev
Log:
Check for feasible runtime check context early

  Instead of generating code for an empty assumed context we bail out
  early. As the number of assumptions we generate increases this becomes
  more and more important. Additionally, this change will allow us to
  hide internal contexts that are only used in runtime checks e.g., a
  boundary context with constraints not suited for simplifications.

Added:
    polly/trunk/test/Isl/Ast/assumed_context_empty_domain_restriction.ll
Removed:
    polly/trunk/test/Isl/CodeGen/assumed_context_empty_domain_restriction.ll
Modified:
    polly/trunk/include/polly/ScopInfo.h
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/lib/CodeGen/IslAst.cpp

Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=245540&r1=245539&r2=245540&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Thu Aug 20 00:58:56 2015
@@ -1045,6 +1045,17 @@ public:
   /// @return The assumed context of this Scop.
   __isl_give isl_set *getAssumedContext() const;
 
+  /// @brief Get the runtime check context for this Scop.
+  ///
+  /// The runtime check context contains all constraints that have to
+  /// hold at runtime for the optimized version to be executed.
+  ///
+  /// @return The runtime check context of this Scop.
+  __isl_give isl_set *getRuntimeCheckContext() const;
+
+  /// @brief Return true if the runtime check context is feasible.
+  bool hasFeasibleRuntimeCheckContext() const;
+
   /// @brief Add assumptions to assumed context.
   ///
   /// The assumptions added will be assumed to hold during the execution of the

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=245540&r1=245539&r2=245540&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Thu Aug 20 00:58:56 2015
@@ -1593,6 +1593,18 @@ __isl_give isl_set *Scop::getAssumedCont
   return isl_set_copy(AssumedContext);
 }
 
+__isl_give isl_set *Scop::getRuntimeCheckContext() const {
+  isl_set *RuntimeCheckContext = getAssumedContext();
+  return RuntimeCheckContext;
+}
+
+bool Scop::hasFeasibleRuntimeCheckContext() const {
+  isl_set *RuntimeCheckContext = getRuntimeCheckContext();
+  bool IsFeasible = !isl_set_is_empty(RuntimeCheckContext);
+  isl_set_free(RuntimeCheckContext);
+  return IsFeasible;
+}
+
 void Scop::addAssumption(__isl_take isl_set *Set) {
   AssumedContext = isl_set_intersect(AssumedContext, Set);
   AssumedContext = isl_set_coalesce(AssumedContext);
@@ -2021,6 +2033,12 @@ bool ScopInfo::runOnRegion(Region *R, RG
 
   DEBUG(scop->print(dbgs()));
 
+  if (!scop->hasFeasibleRuntimeCheckContext()) {
+    delete scop;
+    scop = nullptr;
+    return false;
+  }
+
   if (!PollyUseRuntimeAliasChecks) {
     // Statistics.
     ++ScopFound;

Modified: polly/trunk/lib/CodeGen/IslAst.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslAst.cpp?rev=245540&r1=245539&r2=245540&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslAst.cpp (original)
+++ polly/trunk/lib/CodeGen/IslAst.cpp Thu Aug 20 00:58:56 2015
@@ -335,9 +335,10 @@ buildCondition(__isl_keep isl_ast_build
 
 void IslAst::buildRunCondition(__isl_keep isl_ast_build *Build) {
   // The conditions that need to be checked at run-time for this scop are
-  // available as an isl_set in the AssumedContext from which we can directly
-  // derive a run-time condition.
-  RunCondition = isl_ast_build_expr_from_set(Build, S->getAssumedContext());
+  // available as an isl_set in the runtime check context from which we can
+  // directly derive a run-time condition.
+  RunCondition =
+      isl_ast_build_expr_from_set(Build, S->getRuntimeCheckContext());
 
   // Create the alias checks from the minimal/maximal accesses in each alias
   // group which consists of read only and non read only (read write) accesses.

Added: polly/trunk/test/Isl/Ast/assumed_context_empty_domain_restriction.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/Ast/assumed_context_empty_domain_restriction.ll?rev=245540&view=auto
==============================================================================
--- polly/trunk/test/Isl/Ast/assumed_context_empty_domain_restriction.ll (added)
+++ polly/trunk/test/Isl/Ast/assumed_context_empty_domain_restriction.ll Thu Aug 20 00:58:56 2015
@@ -0,0 +1,54 @@
+; RUN: opt %loadPolly -analyze -polly-detect < %s | FileCheck %s --check-prefix=DETECT
+; RUN: opt %loadPolly -analyze -polly-scops < %s | FileCheck %s --check-prefix=INFO
+; RUN: opt %loadPolly -analyze -polly-ast < %s | FileCheck %s
+;
+; This test used to crash the scalar code generation, now we will bail out after
+; ScopInfo and destory the ScoP as the runtime context is empty.
+;
+; DETECT:  Valid Region for Scop
+;
+; INFO-NOT:  Context:
+; INFO-NOT:  Assumed Context:
+;
+; CHECK-NOT: isl ast
+; CHECK-NOT: if (
+; CHECK-NOT: original code
+;
+ at endposition = external global i32, align 4
+ at Bit = external global [0 x i32], align 4
+ at Init = external global [0 x i32], align 4
+
+define void @maskgen() {
+entry:
+  br label %for.body
+
+for.body:                                         ; preds = %for.body, %entry
+  br i1 undef, label %for.end.310, label %for.body
+
+for.end.310:                                      ; preds = %for.body
+  store i32 undef, i32* @endposition, align 4
+  %sub325 = sub i32 33, 0
+  %0 = load i32, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @Init, i64 0, i64 0), align 4
+  br i1 false, label %for.cond.347.preheader, label %for.body.328.lr.ph
+
+for.body.328.lr.ph:                               ; preds = %for.end.310
+  %1 = sub i32 34, 0
+  br label %for.body.328
+
+for.body.328:                                     ; preds = %for.body.328, %for.body.328.lr.ph
+  %indvars.iv546 = phi i64 [ %indvars.iv.next547, %for.body.328 ], [ 1, %for.body.328.lr.ph ]
+  %2 = phi i32 [ %or331, %for.body.328 ], [ %0, %for.body.328.lr.ph ]
+  %arrayidx330 = getelementptr inbounds [0 x i32], [0 x i32]* @Bit, i64 0, i64 %indvars.iv546
+  %3 = load i32, i32* %arrayidx330, align 4
+  %or331 = or i32 %3, %2
+  %indvars.iv.next547 = add nuw nsw i64 %indvars.iv546, 1
+  %lftr.wideiv = trunc i64 %indvars.iv.next547 to i32
+  %exitcond14 = icmp eq i32 %lftr.wideiv, %1
+  br i1 %exitcond14, label %for.cond.347.preheader, label %for.body.328
+
+for.cond.347.preheader:                           ; preds = %for.cond.347.preheader, %for.body.328, %for.end.310
+  br i1 undef, label %if.end.471, label %for.cond.347.preheader
+
+if.end.471:                                       ; preds = %for.cond.347.preheader
+  ret void
+}

Removed: polly/trunk/test/Isl/CodeGen/assumed_context_empty_domain_restriction.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/assumed_context_empty_domain_restriction.ll?rev=245539&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/assumed_context_empty_domain_restriction.ll (original)
+++ polly/trunk/test/Isl/CodeGen/assumed_context_empty_domain_restriction.ll (removed)
@@ -1,44 +0,0 @@
-; RUN: opt %loadPolly -S -polly-opt-isl -polly-codegen < %s | FileCheck %s
-;
-; This test used to crash the scalar code generation.
-;
-; CHECK: polly.start
-;
- at endposition = external global i32, align 4
- at Bit = external global [0 x i32], align 4
- at Init = external global [0 x i32], align 4
-
-define void @maskgen() {
-entry:
-  br label %for.body
-
-for.body:                                         ; preds = %for.body, %entry
-  br i1 undef, label %for.end.310, label %for.body
-
-for.end.310:                                      ; preds = %for.body
-  store i32 undef, i32* @endposition, align 4
-  %sub325 = sub i32 33, 0
-  %0 = load i32, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @Init, i64 0, i64 0), align 4
-  br i1 false, label %for.cond.347.preheader, label %for.body.328.lr.ph
-
-for.body.328.lr.ph:                               ; preds = %for.end.310
-  %1 = sub i32 34, 0
-  br label %for.body.328
-
-for.body.328:                                     ; preds = %for.body.328, %for.body.328.lr.ph
-  %indvars.iv546 = phi i64 [ %indvars.iv.next547, %for.body.328 ], [ 1, %for.body.328.lr.ph ]
-  %2 = phi i32 [ %or331, %for.body.328 ], [ %0, %for.body.328.lr.ph ]
-  %arrayidx330 = getelementptr inbounds [0 x i32], [0 x i32]* @Bit, i64 0, i64 %indvars.iv546
-  %3 = load i32, i32* %arrayidx330, align 4
-  %or331 = or i32 %3, %2
-  %indvars.iv.next547 = add nuw nsw i64 %indvars.iv546, 1
-  %lftr.wideiv = trunc i64 %indvars.iv.next547 to i32
-  %exitcond14 = icmp eq i32 %lftr.wideiv, %1
-  br i1 %exitcond14, label %for.cond.347.preheader, label %for.body.328
-
-for.cond.347.preheader:                           ; preds = %for.cond.347.preheader, %for.body.328, %for.end.310
-  br i1 undef, label %if.end.471, label %for.cond.347.preheader
-
-if.end.471:                                       ; preds = %for.cond.347.preheader
-  ret void
-}




More information about the llvm-commits mailing list