[polly] r201982 - Do not fail in case we do not have valid dependences

Tobias Grosser tobias at grosser.es
Sun Feb 23 07:15:45 PST 2014


Author: grosser
Date: Sun Feb 23 09:15:44 2014
New Revision: 201982

URL: http://llvm.org/viewvc/llvm-project?rev=201982&view=rev
Log:
Do not fail in case we do not have valid dependences

In case we do not have valid dependences, we do not run dead code elimination or
the schedule optimizer. This fixes an infinite loop in the dead code
elimination (PR12110).

Added:
    polly/trunk/test/DeadCodeElimination/computeout.ll
    polly/trunk/test/ScheduleOptimizer/computeout.ll
Modified:
    polly/trunk/include/polly/Dependences.h
    polly/trunk/lib/Analysis/Dependences.cpp
    polly/trunk/lib/DeadCodeElimination.cpp
    polly/trunk/lib/ScheduleOptimizer.cpp

Modified: polly/trunk/include/polly/Dependences.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/Dependences.h?rev=201982&r1=201981&r2=201982&view=diff
==============================================================================
--- polly/trunk/include/polly/Dependences.h (original)
+++ polly/trunk/include/polly/Dependences.h Sun Feb 23 09:15:44 2014
@@ -91,6 +91,9 @@ public:
   ///              different kinds are 'ored' together.
   isl_union_map *getDependences(int Kinds);
 
+  /// @brief Report if valid dependences are available.
+  bool hasValidDependences();
+
   bool runOnScop(Scop &S);
   void printScop(raw_ostream &OS) const;
   virtual void releaseMemory();

Modified: polly/trunk/lib/Analysis/Dependences.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/Dependences.cpp?rev=201982&r1=201981&r2=201982&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/Dependences.cpp (original)
+++ polly/trunk/lib/Analysis/Dependences.cpp Sun Feb 23 09:15:44 2014
@@ -317,6 +317,7 @@ void Dependences::releaseMemory() {
 }
 
 isl_union_map *Dependences::getDependences(int Kinds) {
+  assert(hasValidDependences() && "No valid dependences available");
   isl_space *Space = isl_union_map_get_space(RAW);
   isl_union_map *Deps = isl_union_map_empty(Space);
 
@@ -334,6 +335,10 @@ isl_union_map *Dependences::getDependenc
   return Deps;
 }
 
+bool Dependences::hasValidDependences() {
+  return (RAW != NULL) && (WAR != NULL) && (WAW != NULL);
+}
+
 void Dependences::getAnalysisUsage(AnalysisUsage &AU) const {
   ScopPass::getAnalysisUsage(AU);
 }

Modified: polly/trunk/lib/DeadCodeElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/DeadCodeElimination.cpp?rev=201982&r1=201981&r2=201982&view=diff
==============================================================================
--- polly/trunk/lib/DeadCodeElimination.cpp (original)
+++ polly/trunk/lib/DeadCodeElimination.cpp Sun Feb 23 09:15:44 2014
@@ -94,9 +94,12 @@ isl_union_set *DeadCodeElim::getLastWrit
 /// combine a certain number of precise steps with one approximating step that
 /// simplifies the life set with an affine hull.
 bool DeadCodeElim::eliminateDeadCode(Scop &S, int PreciseSteps) {
-  isl_union_set *Live = this->getLastWrites(S.getWrites(), S.getSchedule());
-
   Dependences *D = &getAnalysis<Dependences>();
+
+  if (!D->hasValidDependences())
+    return false;
+
+  isl_union_set *Live = this->getLastWrites(S.getWrites(), S.getSchedule());
   isl_union_map *Dep = D->getDependences(Dependences::TYPE_RAW);
   Dep = isl_union_map_reverse(Dep);
 

Modified: polly/trunk/lib/ScheduleOptimizer.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/ScheduleOptimizer.cpp?rev=201982&r1=201981&r2=201982&view=diff
==============================================================================
--- polly/trunk/lib/ScheduleOptimizer.cpp (original)
+++ polly/trunk/lib/ScheduleOptimizer.cpp Sun Feb 23 09:15:44 2014
@@ -431,6 +431,9 @@ isl_union_map *IslScheduleOptimizer::get
 bool IslScheduleOptimizer::runOnScop(Scop &S) {
   Dependences *D = &getAnalysis<Dependences>();
 
+  if (!D->hasValidDependences())
+    return false;
+
   isl_schedule_free(LastSchedule);
   LastSchedule = NULL;
 

Added: polly/trunk/test/DeadCodeElimination/computeout.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/DeadCodeElimination/computeout.ll?rev=201982&view=auto
==============================================================================
--- polly/trunk/test/DeadCodeElimination/computeout.ll (added)
+++ polly/trunk/test/DeadCodeElimination/computeout.ll Sun Feb 23 09:15:44 2014
@@ -0,0 +1,64 @@
+; RUN: opt -S %loadPolly -basicaa -polly-dce -polly-ast -analyze < %s | FileCheck %s
+; RUN: opt -S %loadPolly -basicaa -polly-dce -polly-ast -analyze -polly-dependences-computeout=1 < %s | FileCheck %s -check-prefix=TIMEOUT
+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"
+
+;     for(i = 0; i < 100; i++ )
+; S1:   A[i] = 2;
+;
+;     for (i = 0; i < 10; i++ )
+; S2:   A[i]  = 5;
+;
+;     for (i = 0; i < 200; i++ )
+; S3:   A[i] = 5;
+
+define void @sequential_writes() {
+entry:
+  %A = alloca [200 x i32]
+  br label %S1
+
+S1:
+  %indvar.1 = phi i64 [ 0, %entry ], [ %indvar.next.1, %S1 ]
+  %arrayidx.1 = getelementptr [200 x i32]* %A, i64 0, i64 %indvar.1
+  store i32 2, i32* %arrayidx.1
+  %indvar.next.1 = add i64 %indvar.1, 1
+  %exitcond.1 = icmp ne i64 %indvar.next.1, 100
+  br i1 %exitcond.1, label %S1, label %exit.1
+
+exit.1:
+  br label %S2
+
+S2:
+  %indvar.2 = phi i64 [ 0, %exit.1 ], [ %indvar.next.2, %S2 ]
+  %arrayidx.2 = getelementptr [200 x i32]* %A, i64 0, i64 %indvar.2
+  store i32 5, i32* %arrayidx.2
+  %indvar.next.2 = add i64 %indvar.2, 1
+  %exitcond.2 = icmp ne i64 %indvar.next.2, 10
+  br i1 %exitcond.2, label %S2, label %exit.2
+
+exit.2:
+  br label %S3
+
+S3:
+  %indvar.3 = phi i64 [ 0, %exit.2 ], [ %indvar.next.3, %S3 ]
+  %arrayidx.3 = getelementptr [200 x i32]* %A, i64 0, i64 %indvar.3
+  store i32 7, i32* %arrayidx.3
+  %indvar.next.3 = add i64 %indvar.3, 1
+  %exitcond.3 = icmp ne i64 %indvar.next.3, 200
+  br i1 %exitcond.3, label %S3 , label %exit.3
+
+exit.3:
+  ret void
+}
+
+; CHECK-NOT: Stmt_S
+; CHECK: for (int c1 = 0; c1 <= 199; c1 += 1)
+; CHECK: Stmt_S3(c1);
+
+; TIMEOUT: for (int c1 = 0; c1 <= 99; c1 += 1)
+; TIMEOUT: Stmt_S1(c1);
+; TIMEOUT: for (int c1 = 0; c1 <= 9; c1 += 1)
+; TIMEOUT: Stmt_S2(c1);
+; TIMEOUT: for (int c1 = 0; c1 <= 199; c1 += 1)
+; TIMEOUT: Stmt_S3(c1);
+

Added: polly/trunk/test/ScheduleOptimizer/computeout.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScheduleOptimizer/computeout.ll?rev=201982&view=auto
==============================================================================
--- polly/trunk/test/ScheduleOptimizer/computeout.ll (added)
+++ polly/trunk/test/ScheduleOptimizer/computeout.ll Sun Feb 23 09:15:44 2014
@@ -0,0 +1,70 @@
+; RUN: opt -S %loadPolly -basicaa -polly-opt-isl -polly-opt-fusion=max -polly-ast -analyze < %s | FileCheck %s 
+; RUN: opt -S %loadPolly -basicaa -polly-opt-isl -polly-opt-fusion=max -polly-ast -analyze -polly-dependences-computeout=1 < %s | FileCheck %s -check-prefix=TIMEOUT
+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"
+
+;     for(i = 0; i < 100; i++ )
+; S1:   A[i] = 2;
+;
+;     for (i = 0; i < 10; i++ )
+; S2:   A[i]  = 5;
+;
+;     for (i = 0; i < 200; i++ )
+; S3:   A[i] = 5;
+
+define void @sequential_writes() {
+entry:
+  %A = alloca [200 x i32]
+  br label %S1
+
+S1:
+  %indvar.1 = phi i64 [ 0, %entry ], [ %indvar.next.1, %S1 ]
+  %arrayidx.1 = getelementptr [200 x i32]* %A, i64 0, i64 %indvar.1
+  store i32 2, i32* %arrayidx.1
+  %indvar.next.1 = add i64 %indvar.1, 1
+  %exitcond.1 = icmp ne i64 %indvar.next.1, 100
+  br i1 %exitcond.1, label %S1, label %exit.1
+
+exit.1:
+  br label %S2
+
+S2:
+  %indvar.2 = phi i64 [ 0, %exit.1 ], [ %indvar.next.2, %S2 ]
+  %arrayidx.2 = getelementptr [200 x i32]* %A, i64 0, i64 %indvar.2
+  store i32 5, i32* %arrayidx.2
+  %indvar.next.2 = add i64 %indvar.2, 1
+  %exitcond.2 = icmp ne i64 %indvar.next.2, 10
+  br i1 %exitcond.2, label %S2, label %exit.2
+
+exit.2:
+  br label %S3
+
+S3:
+  %indvar.3 = phi i64 [ 0, %exit.2 ], [ %indvar.next.3, %S3 ]
+  %arrayidx.3 = getelementptr [200 x i32]* %A, i64 0, i64 %indvar.3
+  store i32 7, i32* %arrayidx.3
+  %indvar.next.3 = add i64 %indvar.3, 1
+  %exitcond.3 = icmp ne i64 %indvar.next.3, 200
+  br i1 %exitcond.3, label %S3 , label %exit.3
+
+exit.3:
+  ret void
+}
+
+
+; CHECK: for (int c0 = 0; c0 <= 199; c0 += 1) {
+; CHECK:   if (c0 <= 99) {
+; CHECK:     Stmt_S1(c0);
+; CHECK:     if (c0 <= 9)
+; CHECK:       Stmt_S2(c0);
+; CHECK:   }
+; CHECK:   Stmt_S3(c0);
+; CHECK: }
+
+; TIMEOUT: for (int c1 = 0; c1 <= 99; c1 += 1)
+; TIMEOUT: Stmt_S1(c1);
+; TIMEOUT: for (int c1 = 0; c1 <= 9; c1 += 1)
+; TIMEOUT: Stmt_S2(c1);
+; TIMEOUT: for (int c1 = 0; c1 <= 199; c1 += 1)
+; TIMEOUT: Stmt_S3(c1);
+





More information about the llvm-commits mailing list