summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kruse <llvm@meinersbur.de>2016-03-03 22:10:52 +0000
committerMichael Kruse <llvm@meinersbur.de>2016-03-03 22:10:52 +0000
commitafd2db535118b132b65205360f6c3c3a8bd44291 (patch)
tree0dfcddf1b7bc1a20423af4a29efe0c9cd5f8bf9e
parent09eb4451d2a94995fe985d21ec802b7bb262479c (diff)
downloadbcm5719-llvm-afd2db535118b132b65205360f6c3c3a8bd44291.tar.gz
bcm5719-llvm-afd2db535118b132b65205360f6c3c3a8bd44291.zip
[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. llvm-svn: 262665
-rw-r--r--polly/lib/Support/SCEVValidator.cpp9
-rw-r--r--polly/test/ScopDetect/index_from_unpredictable_loop.ll41
2 files changed, 49 insertions, 1 deletions
diff --git a/polly/lib/Support/SCEVValidator.cpp b/polly/lib/Support/SCEVValidator.cpp
index 24139908c5d..0bece55de0a 100644
--- a/polly/lib/Support/SCEVValidator.cpp
+++ b/polly/lib/Support/SCEVValidator.cpp
@@ -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);
diff --git a/polly/test/ScopDetect/index_from_unpredictable_loop.ll b/polly/test/ScopDetect/index_from_unpredictable_loop.ll
new file mode 100644
index 00000000000..fad59398ac2
--- /dev/null
+++ b/polly/test/ScopDetect/index_from_unpredictable_loop.ll
@@ -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
OpenPOWER on IntegriCloud