[polly] f51427a - [Polly][Unroll] Fix unroll_double test.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 16 07:01:29 PDT 2021


Author: Michael Kruse
Date: 2021-03-16T09:00:42-05:00
New Revision: f51427afb5333e5dd2eb04ea4630037667c64553

URL: https://github.com/llvm/llvm-project/commit/f51427afb5333e5dd2eb04ea4630037667c64553
DIFF: https://github.com/llvm/llvm-project/commit/f51427afb5333e5dd2eb04ea4630037667c64553.diff

LOG: [Polly][Unroll] Fix unroll_double test.

We enumerated the cross product Domain x Scatter, but sorted only be the
scatter key. In case there are are multiple statement instances per
scatter value, the order between statement instances of the same loop
iteration was undefined.

Propertly enumerate and sort only by the scatter value, and group the
domains using the scatter dimension again.

Thanks to Leonard Chan for the report.

Added: 
    

Modified: 
    polly/lib/Transform/ScheduleTreeTransform.cpp
    polly/test/ScheduleOptimizer/ManualOptimization/unroll_double.ll

Removed: 
    


################################################################################
diff  --git a/polly/lib/Transform/ScheduleTreeTransform.cpp b/polly/lib/Transform/ScheduleTreeTransform.cpp
index c6f9c32172be..32cef0ff959d 100644
--- a/polly/lib/Transform/ScheduleTreeTransform.cpp
+++ b/polly/lib/Transform/ScheduleTreeTransform.cpp
@@ -533,13 +533,13 @@ isl::schedule polly::applyFullUnroll(isl::schedule_node BandToUnroll) {
   PartialSchedUAff = PartialSchedUAff.intersect_domain(Domain);
   isl::union_map PartialSchedUMap = isl::union_map(PartialSchedUAff);
 
-  // Make consumable for the following code.
-  // Schedule at the beginning so it is at coordinate 0.
-  isl::union_set PartialSchedUSet = PartialSchedUMap.reverse().wrap();
+  // Enumerator only the scatter elements.
+  isl::union_set ScatterList = PartialSchedUMap.range();
 
-  SmallVector<isl::point, 16> Elts;
+  // Enumerate all loop iterations.
   // TODO: Diagnose if not enumerable or depends on a parameter.
-  PartialSchedUSet.foreach_point([&Elts](isl::point P) -> isl::stat {
+  SmallVector<isl::point, 16> Elts;
+  ScatterList.foreach_point([&Elts](isl::point P) -> isl::stat {
     Elts.push_back(P);
     return isl::stat::ok();
   });
@@ -554,12 +554,10 @@ isl::schedule polly::applyFullUnroll(isl::schedule_node BandToUnroll) {
   // Convert the points to a sequence of filters.
   isl::union_set_list List = isl::union_set_list::alloc(Ctx, Elts.size());
   for (isl::point P : Elts) {
-    isl::basic_set AsSet{P};
-
-    // Throw away the scatter dimension.
-    AsSet = AsSet.unwrap().range();
+    // Determine the domains that map this scatter element.
+    isl::union_set DomainFilter = PartialSchedUMap.intersect_range(P).domain();
 
-    List = List.add(AsSet);
+    List = List.add(DomainFilter);
   }
 
   // Replace original band with unrolled sequence.

diff  --git a/polly/test/ScheduleOptimizer/ManualOptimization/unroll_double.ll b/polly/test/ScheduleOptimizer/ManualOptimization/unroll_double.ll
index a9577271119a..dcd65b357d97 100644
--- a/polly/test/ScheduleOptimizer/ManualOptimization/unroll_double.ll
+++ b/polly/test/ScheduleOptimizer/ManualOptimization/unroll_double.ll
@@ -38,15 +38,25 @@ return:
 
 
 ; CHECK-LABEL: Printing analysis 'Polly - Optimize schedule of SCoP' for region: 'for => return' in function 'func':
+; CHECK: domain: "{ Stmt_body[i0] : 0 <= i0 <= 11 }"
+; CHECK    sequence:
+; CHECK:   - filter: "{ Stmt_body[i0] : 0 <= i0 <= 3 }"
+; CHECK        sequence:
 ; CHECK:       - filter: "{ Stmt_body[0] }"
-; CHECK:       - filter: "{ Stmt_body[1] }"
-; CHECK:       - filter: "{ Stmt_body[2] }"
-; CHECK:       - filter: "{ Stmt_body[3] }"
+; CHECK:       - filter: "{ Stmt_body[i0] : (-1 + i0) mod 4 = 0 }"
+; CHECK:       - filter: "{ Stmt_body[i0] : (2 + i0) mod 4 = 0 }"
+; CHECK:       - filter: "{ Stmt_body[i0] : (1 + i0) mod 4 = 0 }"
+; CHECK    sequence:
+; CHECK:   - filter: "{ Stmt_body[i0] : 4 <= i0 <= 7 }"
+; CHECK        sequence:
 ; CHECK:       - filter: "{ Stmt_body[4] }"
-; CHECK:       - filter: "{ Stmt_body[5] }"
-; CHECK:       - filter: "{ Stmt_body[6] }"
-; CHECK:       - filter: "{ Stmt_body[7] }"
+; CHECK:       - filter: "{ Stmt_body[i0] : (-1 + i0) mod 4 = 0 }"
+; CHECK:       - filter: "{ Stmt_body[i0] : (2 + i0) mod 4 = 0 }"
+; CHECK:       - filter: "{ Stmt_body[i0] : (1 + i0) mod 4 = 0 }"
+; CHECK    sequence:
+; CHECK:   - filter: "{ Stmt_body[i0] : 8 <= i0 <= 11 }"
+; CHECK        sequence:
 ; CHECK:       - filter: "{ Stmt_body[8] }"
-; CHECK:       - filter: "{ Stmt_body[9] }"
-; CHECK:       - filter: "{ Stmt_body[10] }"
-; CHECK:       - filter: "{ Stmt_body[11] }"
+; CHECK:       - filter: "{ Stmt_body[i0] : (-1 + i0) mod 4 = 0 }"
+; CHECK:       - filter: "{ Stmt_body[i0] : (2 + i0) mod 4 = 0 }"
+; CHECK:       - filter: "{ Stmt_body[i0] : (1 + i0) mod 4 = 0 }"


        


More information about the llvm-commits mailing list