summaryrefslogtreecommitdiff
path: root/test/Analysis
diff options
context:
space:
mode:
authorAndrew Trick <atrick@apple.com>2014-05-23 19:47:13 +0000
committerAndrew Trick <atrick@apple.com>2014-05-23 19:47:13 +0000
commitab0d042a74f2e454a516be7a956b091f0ae7e1af (patch)
tree14685ef0e158d3e5bc938ac72e66830f92f60cdf /test/Analysis
parent8b8e384b3cfe35093829530e1772cd1daac62b74 (diff)
downloadllvm-ab0d042a74f2e454a516be7a956b091f0ae7e1af.tar.gz
llvm-ab0d042a74f2e454a516be7a956b091f0ae7e1af.tar.bz2
llvm-ab0d042a74f2e454a516be7a956b091f0ae7e1af.tar.xz
Fix and improve SCEV ComputeBackedgeTankCount.
This is a follow-up to r209358: PR19799: Indvars miscompile due to an incorrect max backedge taken count from SCEV. That fix was incomplete as pointed out by Arnold and Michael Z. The code was also too confusing. It needed a careful rewrite with more unit tests. This version will also happen to optimize more cases. <rdar://17005101> PR19799: Indvars miscompile... git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209545 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis')
-rw-r--r--test/Analysis/ScalarEvolution/max-trip-count.ll56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/Analysis/ScalarEvolution/max-trip-count.ll b/test/Analysis/ScalarEvolution/max-trip-count.ll
index 43a54b4f30..d67d2fab2e 100644
--- a/test/Analysis/ScalarEvolution/max-trip-count.ll
+++ b/test/Analysis/ScalarEvolution/max-trip-count.ll
@@ -124,3 +124,59 @@ for.cond.i: ; preds = %for.body.i
bar.exit: ; preds = %for.cond.i, %for.body.i
ret i32 0
}
+
+; Here we have a must-exit loop latch that is not computabe and a
+; may-exit early exit that can only have one non-exiting iteration
+; before the check is forever skipped.
+;
+; CHECK-LABEL: @cannot_compute_mustexit
+; CHECK: Loop %for.body.i: <multiple exits> Unpredictable backedge-taken count.
+; CHECK: Loop %for.body.i: Unpredictable max backedge-taken count.
+@b = common global i32 0, align 4
+
+define i32 @cannot_compute_mustexit() {
+entry:
+ store i32 -1, i32* @a, align 4
+ br label %for.body.i
+
+for.body.i: ; preds = %for.cond.i, %entry
+ %storemerge1.i = phi i32 [ -1, %entry ], [ %add.i.i, %for.cond.i ]
+ %tobool.i = icmp eq i32 %storemerge1.i, 0
+ %add.i.i = add nsw i32 %storemerge1.i, 2
+ br i1 %tobool.i, label %bar.exit, label %for.cond.i
+
+for.cond.i: ; preds = %for.body.i
+ store i32 %add.i.i, i32* @a, align 4
+ %ld = load volatile i32* @b
+ %cmp.i = icmp ne i32 %ld, 0
+ br i1 %cmp.i, label %for.body.i, label %bar.exit
+
+bar.exit: ; preds = %for.cond.i, %for.body.i
+ ret i32 0
+}
+
+; This loop has two must-exits, both of with dominate the latch. The
+; MaxBECount should be the minimum of them.
+;
+; CHECK-LABEL: @two_mustexit
+; CHECK: Loop %for.body.i: <multiple exits> Unpredictable backedge-taken count.
+; CHECK: Loop %for.body.i: max backedge-taken count is 1
+define i32 @two_mustexit() {
+entry:
+ store i32 -1, i32* @a, align 4
+ br label %for.body.i
+
+for.body.i: ; preds = %for.cond.i, %entry
+ %storemerge1.i = phi i32 [ -1, %entry ], [ %add.i.i, %for.cond.i ]
+ %tobool.i = icmp sgt i32 %storemerge1.i, 0
+ %add.i.i = add nsw i32 %storemerge1.i, 2
+ br i1 %tobool.i, label %bar.exit, label %for.cond.i
+
+for.cond.i: ; preds = %for.body.i
+ store i32 %add.i.i, i32* @a, align 4
+ %cmp.i = icmp slt i32 %storemerge1.i, 3
+ br i1 %cmp.i, label %for.body.i, label %bar.exit
+
+bar.exit: ; preds = %for.cond.i, %for.body.i
+ ret i32 0
+}