2008-03-01 09:15:35 +00:00
|
|
|
; These tests ensure that we can compute the trip count of various forms of
|
2004-04-02 20:26:04 +00:00
|
|
|
; loops. If the trip count of the loop is computable, then we will know what
|
|
|
|
; the exit value of the loop will be for some value, allowing us to substitute
|
|
|
|
; it directly into users outside of the loop, making the loop dead.
|
|
|
|
;
|
2008-05-16 04:27:38 +00:00
|
|
|
; RUN: llvm-as < %s | opt -indvars -loop-deletion -simplifycfg | llvm-dis | not grep br
|
2004-04-02 20:26:04 +00:00
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @linear_setne() {
|
2004-04-02 20:26:04 +00:00
|
|
|
entry:
|
|
|
|
br label %loop
|
2008-03-01 09:15:35 +00:00
|
|
|
|
|
|
|
loop: ; preds = %loop, %entry
|
|
|
|
%i = phi i32 [ 0, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
|
|
|
|
%i.next = add i32 %i, 1 ; <i32> [#uses=1]
|
|
|
|
%c = icmp ne i32 %i, 100 ; <i1> [#uses=1]
|
|
|
|
br i1 %c, label %loop, label %loopexit
|
|
|
|
|
|
|
|
loopexit: ; preds = %loop
|
|
|
|
ret i32 %i
|
2004-04-02 20:26:04 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @linear_setne_2() {
|
2004-04-02 20:26:04 +00:00
|
|
|
entry:
|
|
|
|
br label %loop
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
loop: ; preds = %loop, %entry
|
|
|
|
%i = phi i32 [ 0, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
|
|
|
|
%i.next = add i32 %i, 2 ; <i32> [#uses=1]
|
|
|
|
%c = icmp ne i32 %i, 100 ; <i1> [#uses=1]
|
|
|
|
br i1 %c, label %loop, label %loopexit
|
|
|
|
|
|
|
|
loopexit: ; preds = %loop
|
|
|
|
ret i32 %i
|
|
|
|
}
|
2004-04-02 20:26:04 +00:00
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @linear_setne_overflow() {
|
2004-04-02 20:26:04 +00:00
|
|
|
entry:
|
|
|
|
br label %loop
|
2008-03-01 09:15:35 +00:00
|
|
|
|
|
|
|
loop: ; preds = %loop, %entry
|
|
|
|
%i = phi i32 [ 1024, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
|
|
|
|
%i.next = add i32 %i, 1024 ; <i32> [#uses=1]
|
|
|
|
%c = icmp ne i32 %i, 0 ; <i1> [#uses=1]
|
|
|
|
br i1 %c, label %loop, label %loopexit
|
|
|
|
|
|
|
|
loopexit: ; preds = %loop
|
|
|
|
ret i32 %i
|
2004-04-02 20:26:04 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @linear_setlt() {
|
2004-04-02 20:26:04 +00:00
|
|
|
entry:
|
|
|
|
br label %loop
|
2008-03-01 09:15:35 +00:00
|
|
|
|
|
|
|
loop: ; preds = %loop, %entry
|
|
|
|
%i = phi i32 [ 0, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
|
|
|
|
%i.next = add i32 %i, 1 ; <i32> [#uses=1]
|
|
|
|
%c = icmp slt i32 %i, 100 ; <i1> [#uses=1]
|
|
|
|
br i1 %c, label %loop, label %loopexit
|
|
|
|
|
|
|
|
loopexit: ; preds = %loop
|
|
|
|
ret i32 %i
|
2004-04-02 20:26:04 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @quadratic_setlt() {
|
2004-04-02 20:26:04 +00:00
|
|
|
entry:
|
2008-03-01 09:15:35 +00:00
|
|
|
br label %loop
|
|
|
|
|
|
|
|
loop: ; preds = %loop, %entry
|
|
|
|
%i = phi i32 [ 7, %entry ], [ %i.next, %loop ] ; <i32> [#uses=4]
|
|
|
|
%i.next = add i32 %i, 3 ; <i32> [#uses=1]
|
|
|
|
%i2 = mul i32 %i, %i ; <i32> [#uses=1]
|
|
|
|
%c = icmp slt i32 %i2, 1000 ; <i1> [#uses=1]
|
|
|
|
br i1 %c, label %loop, label %loopexit
|
|
|
|
|
|
|
|
loopexit: ; preds = %loop
|
|
|
|
ret i32 %i
|
2004-04-02 20:26:04 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @chained() {
|
2004-04-02 20:26:04 +00:00
|
|
|
entry:
|
|
|
|
br label %loop
|
2008-03-01 09:15:35 +00:00
|
|
|
|
|
|
|
loop: ; preds = %loop, %entry
|
|
|
|
%i = phi i32 [ 0, %entry ], [ %i.next, %loop ] ; <i32> [#uses=3]
|
|
|
|
%i.next = add i32 %i, 1 ; <i32> [#uses=1]
|
|
|
|
%c = icmp ne i32 %i, 100 ; <i1> [#uses=1]
|
|
|
|
br i1 %c, label %loop, label %loopexit
|
|
|
|
|
|
|
|
loopexit: ; preds = %loop
|
2004-04-02 20:26:04 +00:00
|
|
|
br label %loop2
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
loop2: ; preds = %loop2, %loopexit
|
|
|
|
%j = phi i32 [ %i, %loopexit ], [ %j.next, %loop2 ] ; <i32> [#uses=3]
|
|
|
|
%j.next = add i32 %j, 1 ; <i32> [#uses=1]
|
|
|
|
%c2 = icmp ne i32 %j, 200 ; <i1> [#uses=1]
|
|
|
|
br i1 %c2, label %loop2, label %loopexit2
|
|
|
|
|
|
|
|
loopexit2: ; preds = %loop2
|
|
|
|
ret i32 %j
|
|
|
|
}
|