1 ; These tests ensure that we can compute the trip count of various forms of
2 ; loops. If the trip count of the loop is computable, then we will know what
3 ; the exit value of the loop will be for some value, allowing us to substitute
4 ; it directly into users outside of the loop, making the loop dead.
6 ; RUN: llvm-as < %s | opt -indvars -loop-deletion -simplifycfg | llvm-dis | not grep br
8 define i32 @linear_setne() {
12 loop: ; preds = %loop, %entry
13 %i = phi i32 [ 0, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
14 %i.next = add i32 %i, 1 ; <i32> [#uses=1]
15 %c = icmp ne i32 %i, 100 ; <i1> [#uses=1]
16 br i1 %c, label %loop, label %loopexit
18 loopexit: ; preds = %loop
22 define i32 @linear_setne_2() {
26 loop: ; preds = %loop, %entry
27 %i = phi i32 [ 0, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
28 %i.next = add i32 %i, 2 ; <i32> [#uses=1]
29 %c = icmp ne i32 %i, 100 ; <i1> [#uses=1]
30 br i1 %c, label %loop, label %loopexit
32 loopexit: ; preds = %loop
36 define i32 @linear_setne_overflow() {
40 loop: ; preds = %loop, %entry
41 %i = phi i32 [ 1024, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
42 %i.next = add i32 %i, 1024 ; <i32> [#uses=1]
43 %c = icmp ne i32 %i, 0 ; <i1> [#uses=1]
44 br i1 %c, label %loop, label %loopexit
46 loopexit: ; preds = %loop
50 define i32 @linear_setlt() {
54 loop: ; preds = %loop, %entry
55 %i = phi i32 [ 0, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
56 %i.next = add i32 %i, 1 ; <i32> [#uses=1]
57 %c = icmp slt i32 %i, 100 ; <i1> [#uses=1]
58 br i1 %c, label %loop, label %loopexit
60 loopexit: ; preds = %loop
64 define i32 @quadratic_setlt() {
68 loop: ; preds = %loop, %entry
69 %i = phi i32 [ 7, %entry ], [ %i.next, %loop ] ; <i32> [#uses=4]
70 %i.next = add i32 %i, 3 ; <i32> [#uses=1]
71 %i2 = mul i32 %i, %i ; <i32> [#uses=1]
72 %c = icmp slt i32 %i2, 1000 ; <i1> [#uses=1]
73 br i1 %c, label %loop, label %loopexit
75 loopexit: ; preds = %loop
79 define i32 @chained() {
83 loop: ; preds = %loop, %entry
84 %i = phi i32 [ 0, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
85 %i.next = add i32 %i, 1 ; <i32> [#uses=1]
86 %c = icmp ne i32 %i, 100 ; <i1> [#uses=1]
87 br i1 %c, label %loop, label %loopexit
89 loopexit: ; preds = %loop
92 loop2: ; preds = %loop2, %loopexit
93 %j = phi i32 [ %i, %loopexit ], [ %j.next, %loop2 ] ; <i32> [#uses=3]
94 %j.next = add i32 %j, 1 ; <i32> [#uses=1]
95 %c2 = icmp ne i32 %j, 200 ; <i1> [#uses=1]
96 br i1 %c2, label %loop2, label %loopexit2
98 loopexit2: ; preds = %loop2