[PATCH] D45236: [Polly][IslAst] Fix minimal dependence distance.

Huihui Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 3 16:50:54 PDT 2018


huihuiz updated this revision to Diff 140886.
huihuiz marked an inline comment as done.
huihuiz added a comment.

add  -instnamer to unit test


Repository:
  rL LLVM

https://reviews.llvm.org/D45236

Files:
  lib/Analysis/DependenceInfo.cpp
  lib/CodeGen/IslAst.cpp
  test/Isl/Ast/dependence_distance_minimal.ll


Index: test/Isl/Ast/dependence_distance_minimal.ll
===================================================================
--- /dev/null
+++ test/Isl/Ast/dependence_distance_minimal.ll
@@ -0,0 +1,57 @@
+; RUN: opt %loadPolly -polly-ast -polly-ast-detect-parallel -analyze -instnamer < %s | FileCheck %s
+;
+; The minimal dependence distance of the innermost loop should be 1 instead of 250.
+; CHECK:    #pragma minimal dependence distance: 1
+; CHECK:    for (int c0 = 0; c0 <= 499; c0 += 1)
+; CHECK:      #pragma minimal dependence distance: 1
+; CHECK:      for (int c1 = 0; c1 <= 998; c1 += 1)
+; CHECK:        Stmt1(c0, c1);
+; CHECK:        Stmt1_b(c0, c1);
+;
+;    void foo (int *A, int *B) {
+;      for (int i=0; i < 500; i++) {
+;        for (int j=0; j < 1000; j++) {
+;          B[i] = B[i] + 1;
+;          A[j] += A[j % 250];
+;        }
+;      }
+;    }
+;
+target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
+
+; Function Attrs: norecurse nounwind
+define void @foo(i32* nocapture, i32* nocapture) {
+  br label %3
+
+; <label>:3:                                      ; preds = %2
+  br label %5
+
+; <label>:4:                                      ; preds = %8
+  ret void
+
+; <label>:5:                                      ; preds = %8, %3
+  %6 = phi i32 [ 0, %3 ], [ %9, %8 ]
+  %7 = getelementptr inbounds i32, i32* %1, i32 %6
+  br label %11
+
+; <label>:8:                                      ; preds = %11
+  %9 = add nuw nsw i32 %6, 1
+  %10 = icmp eq i32 %9, 500
+  br i1 %10, label %4, label %5
+
+; <label>:11:                                     ; preds = %11, %5
+  %12 = phi i32 [ 1, %5 ], [ %21, %11 ]
+  %13 = load i32, i32* %7, align 4
+  %14 = add nsw i32 %13, 1
+  store i32 %14, i32* %7, align 4
+  %15 = urem i32 %12, 250
+  %16 = getelementptr inbounds i32, i32* %0, i32 %15
+  %17 = load i32, i32* %16, align 4
+  %18 = getelementptr inbounds i32, i32* %0, i32 %12
+  %19 = load i32, i32* %18, align 4
+  %20 = add nsw i32 %19, %17
+  store i32 %20, i32* %18, align 4
+  %21 = add nuw nsw i32 %12, 1
+  %22 = icmp eq i32 %21, 1000
+  br i1 %22, label %8, label %11
+}
Index: lib/CodeGen/IslAst.cpp
===================================================================
--- lib/CodeGen/IslAst.cpp
+++ lib/CodeGen/IslAst.cpp
@@ -219,9 +219,14 @@
   isl_union_map *Deps = D->getDependences(
       Dependences::TYPE_RAW | Dependences::TYPE_WAW | Dependences::TYPE_WAR);
 
-  if (!D->isParallel(Schedule, Deps, &NodeInfo->MinimalDependenceDistance) &&
-      !isl_union_map_free(Schedule))
+  if (!D->isParallel(Schedule, Deps)) {
+    isl_union_map *DepsAll =
+        D->getDependences(Dependences::TYPE_RAW | Dependences::TYPE_WAW |
+                          Dependences::TYPE_WAR | Dependences::TYPE_TC_RED);
+    D->isParallel(Schedule, DepsAll, &NodeInfo->MinimalDependenceDistance);
+    isl_union_map_free(Schedule);
     return false;
+  }
 
   isl_union_map *RedDeps = D->getDependences(Dependences::TYPE_TC_RED);
   if (!D->isParallel(Schedule, RedDeps))
Index: lib/Analysis/DependenceInfo.cpp
===================================================================
--- lib/Analysis/DependenceInfo.cpp
+++ lib/Analysis/DependenceInfo.cpp
@@ -646,7 +646,8 @@
 
     // Step 4)
     addPrivatizationDependences();
-  }
+  } else
+    TC_RED = isl_union_map_empty(isl_union_map_get_space(RED));
 
   DEBUG({
     dbgs() << "Final Wrapped Dependences:\n";


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45236.140886.patch
Type: text/x-patch
Size: 3414 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180403/bff28e78/attachment.bin>


More information about the llvm-commits mailing list