summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/LoopUnroll
diff options
context:
space:
mode:
authorHaicheng Wu <haicheng@codeaurora.org>2016-10-12 21:29:38 +0000
committerHaicheng Wu <haicheng@codeaurora.org>2016-10-12 21:29:38 +0000
commit1ef17e90b20a2b6056ab27f022b320cb008899ca (patch)
treea8f48bb614546ebce2c76a2f381a64118f494d9a /llvm/test/Transforms/LoopUnroll
parentd62669d7919a25329a7b9f212c48103dbcc5ca0f (diff)
downloadbcm5719-llvm-1ef17e90b20a2b6056ab27f022b320cb008899ca.tar.gz
bcm5719-llvm-1ef17e90b20a2b6056ab27f022b320cb008899ca.zip
Reapply "[LoopUnroll] Use the upper bound of the loop trip count to fullly unroll a loop"
Reappy r284044 after revert in r284051. Krzysztof fixed the error in r284049. The original summary: This patch tries to fully unroll loops having break statement like this for (int i = 0; i < 8; i++) { if (a[i] == value) { found = true; break; } } GCC can fully unroll such loops, but currently LLVM cannot because LLVM only supports loops having exact constant trip counts. The upper bound of the trip count can be obtained from calling ScalarEvolution::getMaxBackedgeTakenCount(). Part of the patch is the refactoring work in SCEV to prevent duplicating code. The feature of using the upper bound is enabled under the same circumstance when runtime unrolling is enabled since both are used to unroll loops without knowing the exact constant trip count. llvm-svn: 284053
Diffstat (limited to 'llvm/test/Transforms/LoopUnroll')
-rw-r--r--llvm/test/Transforms/LoopUnroll/AArch64/full-unroll-trip-count-upper-bound.ll43
1 files changed, 43 insertions, 0 deletions
diff --git a/llvm/test/Transforms/LoopUnroll/AArch64/full-unroll-trip-count-upper-bound.ll b/llvm/test/Transforms/LoopUnroll/AArch64/full-unroll-trip-count-upper-bound.ll
new file mode 100644
index 00000000000..5c70a2668db
--- /dev/null
+++ b/llvm/test/Transforms/LoopUnroll/AArch64/full-unroll-trip-count-upper-bound.ll
@@ -0,0 +1,43 @@
+; RUN: opt -loop-unroll -S -mtriple aarch64 -mcpu=cortex-a57 %s | FileCheck %s -check-prefix=UNROLL
+; RUN: opt -loop-unroll -unroll-max-upperbound=0 -S -mtriple aarch64 -mcpu=cortex-a57 %s | FileCheck %s -check-prefix=NOUNROLL
+
+; This IR comes from this C code:
+;
+; for (int i = 0; i < 4; i++) {
+; if (src[i] == 1) {
+; *dst = i;
+; break;
+; }
+; }
+;
+; This test is meant to check that this loop is unrolled into four iterations.
+
+; UNROLL-LABEL: @test
+; UNROLL: load i32, i32*
+; UNROLL: load i32, i32*
+; UNROLL: load i32, i32*
+; UNROLL: load i32, i32*
+; UNROLL-NOT: load i32, i32*
+; NOUNROLL-LABEL: @test
+; NOUNROLL: load i32, i32*
+; NOUNROLL-NOT: load i32, i32*
+
+define void @test(i32* %dst, i32* %src) {
+entry:
+ br label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %i = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ %0 = sext i32 %i to i64
+ %1 = getelementptr inbounds i32, i32* %src, i64 %0
+ %2 = load i32, i32* %1
+ %inc = add nsw i32 %i, 1
+ %cmp1 = icmp slt i32 %inc, 4
+ %cmp3 = icmp eq i32 %2, 1
+ %or.cond = and i1 %cmp3, %cmp1
+ br i1 %or.cond, label %for.body, label %exit
+
+exit: ; preds = %for.body
+ store i32 %i, i32* %dst
+ ret void
+}
OpenPOWER on IntegriCloud