[polly] r262665 - [SCEVValidator] Fix loop exit values considered affine.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 3 14:10:53 PST 2016


Author: meinersbur
Date: Thu Mar  3 16:10:52 2016
New Revision: 262665

URL: http://llvm.org/viewvc/llvm-project?rev=262665&view=rev
Log:
[SCEVValidator] Fix loop exit values considered affine.

Index calculations can use the last value that come out of a loop.
Ideally, ScalarEvolution can compute that exit value directly without
depending on the loop induction variable, but not in all cases.

This changes isAffine to not consider such loop exit values as affine to
avoid that SCEVExpander adds uses of the original loop induction
variable.

This fix is analogous to r262404 that applies to general uses of loop
exit values instead of index expressions and loop bouds as in this
patch.

This reduces the number of LNT test-suite fails with
-polly-position=before-vectorizer -polly-unprofitable
from 10 to 8.

Added:
    polly/trunk/test/ScopDetect/index_from_unpredictable_loop.ll
Modified:
    polly/trunk/lib/Support/SCEVValidator.cpp

Modified: polly/trunk/lib/Support/SCEVValidator.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/SCEVValidator.cpp?rev=262665&r1=262664&r2=262665&view=diff
==============================================================================
--- polly/trunk/lib/Support/SCEVValidator.cpp (original)
+++ polly/trunk/lib/Support/SCEVValidator.cpp Thu Mar  3 16:10:52 2016
@@ -267,7 +267,14 @@ public:
     if (!Recurrence.isValid())
       return Recurrence;
 
-    if (R->contains(Expr->getLoop())) {
+    auto *L = Expr->getLoop();
+    if (R->contains(L) && (!Scope || !L->contains(Scope))) {
+      DEBUG(dbgs() << "INVALID: AddRec out of a loop whose exit value is not "
+                      "synthesizable");
+      return ValidatorResult(SCEVType::INVALID);
+    }
+
+    if (R->contains(L)) {
       if (Recurrence.isINT()) {
         ValidatorResult Result(SCEVType::IV);
         Result.addParamsFrom(Start);

Added: polly/trunk/test/ScopDetect/index_from_unpredictable_loop.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopDetect/index_from_unpredictable_loop.ll?rev=262665&view=auto
==============================================================================
--- polly/trunk/test/ScopDetect/index_from_unpredictable_loop.ll (added)
+++ polly/trunk/test/ScopDetect/index_from_unpredictable_loop.ll Thu Mar  3 16:10:52 2016
@@ -0,0 +1,41 @@
+; RUN: opt %loadPolly -polly-scops -analyze < %s | FileCheck %s --check-prefix=AFFINE
+; RUN: opt %loadPolly -polly-scops -polly-allow-nonaffine -analyze < %s | FileCheck %s --check-prefix=NONAFFINE
+
+; The loop for.body => for.inc has an unpredictable iteration count could due to
+; the undef start value that it is compared to. Therefore the array element
+; %arrayidx101 that depends on that exit value cannot be affine.
+; Derived from test-suite/MultiSource/Benchmarks/BitBench/uuencode/uuencode.c
+
+define void @encode_line(i8* nocapture readonly %input, i32 %octets) {
+entry:
+  br i1 undef, label %for.body, label %for.end
+
+for.body:
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
+  %octets.addr.02 = phi i32 [ undef, %for.inc ], [ %octets, %entry ]
+  br i1 false, label %for.inc, label %if.else
+
+if.else:
+  %cond = icmp eq i32 %octets.addr.02, 2
+  br i1 %cond, label %if.then84, label %for.end
+
+if.then84:
+  %0 = add nsw i64 %indvars.iv, 1
+  %arrayidx101 = getelementptr inbounds i8, i8* %input, i64 %0
+  %1 = load i8, i8* %arrayidx101, align 1
+  br label %for.end
+
+for.inc:
+  %cmp = icmp sgt i32 %octets.addr.02, 3
+  %indvars.iv.next = add nsw i64 %indvars.iv, 3
+  br i1 %cmp, label %for.body, label %for.end
+
+for.end:
+  ret void
+}
+
+
+; AFFINE-NOT: Function: encode_line
+
+; NONAFFINE:      Function: encode_line
+; NONAFFINE-NEXT: Region: %for.body---%for.end




More information about the llvm-commits mailing list