summaryrefslogtreecommitdiff
path: root/test/Analysis
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2013-10-28 07:30:06 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2013-10-28 07:30:06 +0000
commit19ea37059aaea8104ea6017abc9f1bbed610b7f2 (patch)
tree6be77c455a3a706963179bac69a25112aba025fc /test/Analysis
parent1fe9069d53f586963d61523f7c5a7d41d80a9d8b (diff)
downloadllvm-19ea37059aaea8104ea6017abc9f1bbed610b7f2.tar.gz
llvm-19ea37059aaea8104ea6017abc9f1bbed610b7f2.tar.bz2
llvm-19ea37059aaea8104ea6017abc9f1bbed610b7f2.tar.xz
SCEV: Make the final add of an inbounds GEP nuw if we know that the index is positive.
We can't do this for the general case as saying a GEP with a negative index doesn't have unsigned wrap isn't valid for negative indices. %gep = getelementptr inbounds i32* %p, i64 -1 But an inbounds GEP cannot run past the end of address space. So we check for the very common case of a positive index and make GEPs derived from that NUW. Together with Andy's recent non-unit stride work this lets us analyze loops like void foo3(int *a, int *b) { for (; a < b; a++) {} } PR12375, PR12376. Differential Revision: http://llvm-reviews.chandlerc.com/D2033 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193514 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis')
-rw-r--r--test/Analysis/ScalarEvolution/nsw.ll40
1 files changed, 38 insertions, 2 deletions
diff --git a/test/Analysis/ScalarEvolution/nsw.ll b/test/Analysis/ScalarEvolution/nsw.ll
index 659cf4f8da..05992eadba 100644
--- a/test/Analysis/ScalarEvolution/nsw.ll
+++ b/test/Analysis/ScalarEvolution/nsw.ll
@@ -62,11 +62,11 @@ for.body.lr.ph.i.i: ; preds = %entry
for.body.i.i: ; preds = %for.body.i.i, %for.body.lr.ph.i.i
%__first.addr.02.i.i = phi i32* [ %begin, %for.body.lr.ph.i.i ], [ %ptrincdec.i.i, %for.body.i.i ]
; CHECK: %__first.addr.02.i.i
-; CHECK-NEXT: --> {%begin,+,4}<nw><%for.body.i.i>
+; CHECK-NEXT: --> {%begin,+,4}<nuw><%for.body.i.i>
store i32 0, i32* %__first.addr.02.i.i, align 4
%ptrincdec.i.i = getelementptr inbounds i32* %__first.addr.02.i.i, i64 1
; CHECK: %ptrincdec.i.i
-; CHECK-NEXT: --> {(4 + %begin),+,4}<nw><%for.body.i.i>
+; CHECK-NEXT: --> {(4 + %begin),+,4}<nuw><%for.body.i.i>
%cmp.i.i = icmp eq i32* %ptrincdec.i.i, %end
br i1 %cmp.i.i, label %for.cond.for.end_crit_edge.i.i, label %for.body.i.i
@@ -122,3 +122,39 @@ exit:
%result = phi i32 [ %a, %entry ], [ %tmp2, %greater ]
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)
+define i32 @PR12375(i32* readnone %arg) {
+bb:
+ %tmp = getelementptr inbounds i32* %arg, i64 2
+ br label %bb1
+
+bb1: ; preds = %bb1, %bb
+ %tmp2 = phi i32* [ %arg, %bb ], [ %tmp5, %bb1 ]
+ %tmp3 = phi i32 [ 0, %bb ], [ %tmp4, %bb1 ]
+ %tmp4 = add nsw i32 %tmp3, 1
+ %tmp5 = getelementptr inbounds i32* %tmp2, i64 1
+ %tmp6 = icmp ult i32* %tmp5, %tmp
+ br i1 %tmp6, label %bb1, label %bb7
+
+bb7: ; preds = %bb1
+ ret i32 %tmp4
+}
+
+; CHECK-LABEL: PR12376
+; CHECK: --> {(4 + %arg),+,4}<nuw><%bb2> Exits: (4 + (4 * ((3 + (-1 * %arg) + (%arg umax %arg1)) /u 4)) + %arg)
+define void @PR12376(i32* nocapture %arg, i32* nocapture %arg1) {
+bb:
+ br label %bb2
+
+bb2: ; preds = %bb2, %bb
+ %tmp = phi i32* [ %arg, %bb ], [ %tmp4, %bb2 ]
+ %tmp3 = icmp ult i32* %tmp, %arg1
+ %tmp4 = getelementptr inbounds i32* %tmp, i64 1
+ br i1 %tmp3, label %bb2, label %bb5
+
+bb5: ; preds = %bb2
+ ret void
+}