summaryrefslogtreecommitdiffstats
path: root/llvm/test
diff options
context:
space:
mode:
authorBradley Smith <bradley.smith@arm.com>2014-10-31 11:40:32 +0000
committerBradley Smith <bradley.smith@arm.com>2014-10-31 11:40:32 +0000
commit9992b167aea97de3a13bf0f0b95189a4e5f4bf92 (patch)
tree90c4c43d7668cb2d3185a26320e356db69a589bd /llvm/test
parentc8c2ea2854bb750374158ff1b9c3cd7ccd9481f1 (diff)
downloadbcm5719-llvm-9992b167aea97de3a13bf0f0b95189a4e5f4bf92.tar.gz
bcm5719-llvm-9992b167aea97de3a13bf0f0b95189a4e5f4bf92.zip
[SCEV] Improve Scalar Evolution's use of no {un,}signed wrap flags
In a case where we have a no {un,}signed wrap flag on the increment, if RHS - Start is constant then we can avoid inserting a max operation bewteen the two, since we can statically determine which is greater. This allows us to unroll loops such as: void testcase3(int v) { for (int i=v; i<=v+1; ++i) f(i); } llvm-svn: 220960
Diffstat (limited to 'llvm/test')
-rw-r--r--llvm/test/Analysis/ScalarEvolution/nsw.ll23
-rw-r--r--llvm/test/Transforms/LoopUnroll/nsw-tripcount.ll32
2 files changed, 53 insertions, 2 deletions
diff --git a/llvm/test/Analysis/ScalarEvolution/nsw.ll b/llvm/test/Analysis/ScalarEvolution/nsw.ll
index 05992eadbac..d776a5a5da7 100644
--- a/llvm/test/Analysis/ScalarEvolution/nsw.ll
+++ b/llvm/test/Analysis/ScalarEvolution/nsw.ll
@@ -123,9 +123,8 @@ exit:
ret i32 %result
}
-; TODO: This could fold down to '1'
; CHECK-LABEL: PR12375
-; CHECK: --> {(4 + %arg),+,4}<nuw><%bb1> Exits: (4 + (4 * ((-1 + (-1 * %arg) + ((4 + %arg) umax (8 + %arg)<nsw>)) /u 4)) + %arg)
+; CHECK: --> {(4 + %arg),+,4}<nuw><%bb1> Exits: (8 + %arg)<nsw>
define i32 @PR12375(i32* readnone %arg) {
bb:
%tmp = getelementptr inbounds i32* %arg, i64 2
@@ -158,3 +157,23 @@ bb2: ; preds = %bb2, %bb
bb5: ; preds = %bb2
ret void
}
+
+declare void @f(i32)
+
+; CHECK-LABEL: nswnowrap
+; CHECK: --> {(1 + %v),+,1}<nsw><%for.body> Exits: (2 + %v)
+define void @nswnowrap(i32 %v) {
+entry:
+ %add = add nsw i32 %v, 1
+ br label %for.body
+
+for.body:
+ %i.04 = phi i32 [ %v, %entry ], [ %inc, %for.body ]
+ %inc = add nsw i32 %i.04, 1
+ tail call void @f(i32 %i.04)
+ %cmp = icmp slt i32 %i.04, %add
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end:
+ ret void
+}
diff --git a/llvm/test/Transforms/LoopUnroll/nsw-tripcount.ll b/llvm/test/Transforms/LoopUnroll/nsw-tripcount.ll
new file mode 100644
index 00000000000..98cab32a42a
--- /dev/null
+++ b/llvm/test/Transforms/LoopUnroll/nsw-tripcount.ll
@@ -0,0 +1,32 @@
+; RUN: opt -loop-unroll -S %s | FileCheck %s
+
+; extern void f(int);
+; void test1(int v) {
+; for (int i=v; i<=v+1; ++i)
+; f(i);
+; }
+;
+; We can use the nsw information to see that the tripcount will be 2, so the
+; loop should be unrolled as this is always beneficial
+
+declare void @f(i32)
+
+; CHECK-LABEL: @test1
+define void @test1(i32 %v) {
+entry:
+ %add = add nsw i32 %v, 1
+ br label %for.body
+
+for.body:
+ %i.04 = phi i32 [ %v, %entry ], [ %inc, %for.body ]
+ tail call void @f(i32 %i.04)
+ %inc = add nsw i32 %i.04, 1
+ %cmp = icmp slt i32 %i.04, %add
+ br i1 %cmp, label %for.body, label %for.end
+
+; CHECK: call void @f
+; CHECK-NOT: br i1
+; CHECK: call void @f
+for.end:
+ ret void
+}
OpenPOWER on IntegriCloud