[PATCH] D21591: [Polly] Fix assertion due to buildMemoryAccess.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 27 15:27:05 PDT 2016


Meinersbur accepted this revision.
This revision is now accepted and ready to land.

================
Comment at: lib/Analysis/ScopInfo.cpp:4372-4375
@@ -4364,1 +4371,6 @@
   const InvariantLoadsSetTy &ScopRIL = scop->getRequiredInvariantLoads();
+  // If the loop is nonaffine/boxed, return the first non-boxed surrounding loop
+  // for polly. If the loop is affine, return the loop itself. Do not call
+  // `getSCEVAtScope()` on the result of `getFirstNonBoxedLoopFor()`, as we need
+  // to analyze memory access of the nonaffine/boxed loops.
+  L = getFirstNonBoxedLoopFor(L, LI, scop->getBoxedLoops());
----------------
It would be better if this was the added to the documentation of getFirstNonBoxedLoopFor() instead of copying it three times.

`polly` -> `Polly` as it is a name

The backticks are Markdown syntax. They work in Phabricator but not in plain text/Doxygen.

> as we need to analyze _the_ memory access_es_ of the nonaffine/boxed loops.

Please also describe the effect of getSCEVAtScope on it (it tries to remove the SCEVAddRecExpr to get an explicit expression for a use /outside/ the loop; the use is still inside and would not be detectable by SCEVValidator anymore)

================
Comment at: test/DependenceInfo/nonaffine-condition-buildMemoryAccess.ll:1-74
@@ +1,74 @@
+; RUN: opt %loadPolly -polly-codegen -polly-allow-nonaffine-loops -polly-allow-nonaffine -debug-only=polly-dependence < %s 2>&1 | FileCheck %s 
+
+; CHECK:        MayWriteAccess :=   [Reduction Type: NONE] [Scalar: 0]
+; CHECK-NEXT:       { Stmt_for_body__TO__for_inc11[i0] -> MemRef_A[o0] : 0 <= o0 <= 699 };
+; CHECK-NEXT:   MayWriteAccess :=   [Reduction Type: NONE] [Scalar: 0]
+; CHECK-NEXT:       { Stmt_for_body__TO__for_inc11[i0] -> MemRef_B[700] };
+
+ 
+; The if condition C[i] is a non-affine condition, which make the nested loop boxed. The memory access for A should be a range A[0...699]. The memory access for B should be simplified to B[700].
+;
+; int A[1000], B[1000], C[1000];
+;
+; void foo(int n, int m, int N) {
+;   for (int i = 0; i < 500; i+=1) { /* affine loop */
+;      C[i] += i;
+;      if (C[i]) { /* non-affine subregion */
+;          int j;
+;          for (j = 0; j < 700; j+=1) { /* boxed loop */
+;            A[j] = 1;
+;          }
+;          B[j] = 2;
+;      }
+;    }
+; }
+
+
+target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
+
+ at C = common global [1000 x i32] zeroinitializer, align 4
+ at A = common global [1000 x i32] zeroinitializer, align 4
+ at B = common global [1000 x i32] zeroinitializer, align 4
+
+; Function Attrs: norecurse nounwind
+define void @foo(i32 %n, i32 %m, i32 %N) #0 {
+entry:
+  br label %entry.split
+
+entry.split:                                      ; preds = %entry
+  br label %for.body
+
+for.cond.cleanup:                                 ; preds = %for.inc11
+  ret void
+
+for.body:                                         ; preds = %for.inc11, %entry.split
+  %indvars.iv25 = phi i64 [ 0, %entry.split ], [ %indvars.iv.next26, %for.inc11 ]
+  %arrayidx = getelementptr inbounds [1000 x i32], [1000 x i32]* @C, i64 0, i64 %indvars.iv25
+  %0 = load i32, i32* %arrayidx, align 4
+  %1 = trunc i64 %indvars.iv25 to i32
+  %add = add nsw i32 %0, %1
+  store i32 %add, i32* %arrayidx, align 4
+  %tobool = icmp eq i32 %add, 0
+  br i1 %tobool, label %for.inc11, label %for.body5.preheader
+
+for.body5.preheader:                              ; preds = %for.body
+  br label %for.body5
+
+for.body5:                                        ; preds = %for.body5.preheader, %for.body5
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body5 ], [ 0, %for.body5.preheader ]
+  %arrayidx7 = getelementptr inbounds [1000 x i32], [1000 x i32]* @A, i64 0, i64 %indvars.iv
+  store i32 1, i32* %arrayidx7, align 4
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %exitcond = icmp eq i64 %indvars.iv, 699
+  br i1 %exitcond, label %for.end, label %for.body5
+
+for.end:                                          ; preds = %for.body5
+  store i32 2, i32* getelementptr inbounds ([1000 x i32], [1000 x i32]* @B, i64 0, i64 700), align 4
+  br label %for.inc11
+
+for.inc11:                                        ; preds = %for.body, %for.end
+  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
+  %exitcond27 = icmp eq i64 %indvars.iv25, 499
+  br i1 %exitcond27, label %for.cond.cleanup, label %for.body
+}
+
----------------
Thanks a lot for the test case!


Repository:
  rL LLVM

http://reviews.llvm.org/D21591





More information about the llvm-commits mailing list