diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2008-11-18 15:10:54 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2008-11-18 15:10:54 +0000 |
commit | dd643f26c43d162e905a07bf0826680aa10f7161 (patch) | |
tree | 6250d940d0206fd446630ab36212fdf38e50a083 /test/Analysis | |
parent | 5734450d40fe5546eb98c0d856d73c3321eaf5d2 (diff) | |
download | external_llvm-dd643f26c43d162e905a07bf0826680aa10f7161.zip external_llvm-dd643f26c43d162e905a07bf0826680aa10f7161.tar.gz external_llvm-dd643f26c43d162e905a07bf0826680aa10f7161.tar.bz2 |
Add a utility function that detects whether a loop is guaranteed to be finite.
Use it to safely handle less-than-or-equals-to exit conditions in loops. These
also occur when the loop exit branch is exit on true because SCEV inverses the
icmp predicate.
Use it again to handle non-zero strides, but only with an unsigned comparison
in the exit condition.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@59528 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis')
-rw-r--r-- | test/Analysis/ScalarEvolution/2008-11-18-LessThanOrEqual.ll | 31 | ||||
-rw-r--r-- | test/Analysis/ScalarEvolution/2008-11-18-Stride1.ll | 30 | ||||
-rw-r--r-- | test/Analysis/ScalarEvolution/2008-11-18-Stride2.ll | 30 |
3 files changed, 91 insertions, 0 deletions
diff --git a/test/Analysis/ScalarEvolution/2008-11-18-LessThanOrEqual.ll b/test/Analysis/ScalarEvolution/2008-11-18-LessThanOrEqual.ll new file mode 100644 index 0000000..6bacfab --- /dev/null +++ b/test/Analysis/ScalarEvolution/2008-11-18-LessThanOrEqual.ll @@ -0,0 +1,31 @@ +; RUN: llvm-as < %s | opt -analyze -scalar-evolution |& \ +; RUN: grep {Loop bb: (7 + (-1 \\* %argc)) iterations!} + +define i32 @main(i32 %argc, i8** %argv) nounwind { +entry: + %0 = icmp ugt i32 %argc, 7 ; <i1> [#uses=1] + br i1 %0, label %bb2, label %bb.nph + +bb.nph: ; preds = %entry + br label %bb + +bb: ; preds = %bb.nph, %bb1 + %indvar = phi i32 [ 0, %bb.nph ], [ %indvar.next, %bb1 ] ; <i32> [#uses=2] + %argc_addr.04 = add i32 %indvar, %argc ; <i32> [#uses=1] + tail call void (...)* @Test() nounwind + %1 = add i32 %argc_addr.04, 1 ; <i32> [#uses=1] + br label %bb1 + +bb1: ; preds = %bb + %phitmp = icmp ugt i32 %1, 7 ; <i1> [#uses=1] + %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=1] + br i1 %phitmp, label %bb1.bb2_crit_edge, label %bb + +bb1.bb2_crit_edge: ; preds = %bb1 + br label %bb2 + +bb2: ; preds = %bb1.bb2_crit_edge, %entry + ret i32 0 +} + +declare void @Test(...) diff --git a/test/Analysis/ScalarEvolution/2008-11-18-Stride1.ll b/test/Analysis/ScalarEvolution/2008-11-18-Stride1.ll new file mode 100644 index 0000000..78cda0e --- /dev/null +++ b/test/Analysis/ScalarEvolution/2008-11-18-Stride1.ll @@ -0,0 +1,30 @@ +; RUN: llvm-as < %s | opt -analyze -scalar-evolution |& grep {/u 3} + +define i32 @f(i32 %x) nounwind readnone { +entry: + %0 = icmp ugt i32 %x, 4 ; <i1> [#uses=1] + br i1 %0, label %bb.nph, label %bb2 + +bb.nph: ; preds = %entry + br label %bb + +bb: ; preds = %bb.nph, %bb1 + %indvar = phi i32 [ 0, %bb.nph ], [ %indvar.next, %bb1 ] ; <i32> [#uses=2] + %tmp = mul i32 %indvar, -3 ; <i32> [#uses=1] + %x_addr.04 = add i32 %tmp, %x ; <i32> [#uses=1] + %1 = add i32 %x_addr.04, -3 ; <i32> [#uses=2] + br label %bb1 + +bb1: ; preds = %bb + %2 = icmp ugt i32 %1, 4 ; <i1> [#uses=1] + %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=1] + br i1 %2, label %bb, label %bb1.bb2_crit_edge + +bb1.bb2_crit_edge: ; preds = %bb1 + %.lcssa = phi i32 [ %1, %bb1 ] ; <i32> [#uses=1] + br label %bb2 + +bb2: ; preds = %bb1.bb2_crit_edge, %entry + %x_addr.0.lcssa = phi i32 [ %.lcssa, %bb1.bb2_crit_edge ], [ %x, %entry ] ; <i32> [#uses=1] + ret i32 %x_addr.0.lcssa +} diff --git a/test/Analysis/ScalarEvolution/2008-11-18-Stride2.ll b/test/Analysis/ScalarEvolution/2008-11-18-Stride2.ll new file mode 100644 index 0000000..a8db01e --- /dev/null +++ b/test/Analysis/ScalarEvolution/2008-11-18-Stride2.ll @@ -0,0 +1,30 @@ +; RUN: llvm-as < %s | opt -analyze -scalar-evolution |& grep {/u 3} + +define i32 @f(i32 %x) nounwind readnone { +entry: + %0 = icmp ugt i32 %x, 999 ; <i1> [#uses=1] + br i1 %0, label %bb2, label %bb.nph + +bb.nph: ; preds = %entry + br label %bb + +bb: ; preds = %bb.nph, %bb1 + %indvar = phi i32 [ 0, %bb.nph ], [ %indvar.next, %bb1 ] ; <i32> [#uses=2] + %tmp = mul i32 %indvar, 3 ; <i32> [#uses=1] + %x_addr.04 = add i32 %tmp, %x ; <i32> [#uses=1] + %1 = add i32 %x_addr.04, 3 ; <i32> [#uses=2] + br label %bb1 + +bb1: ; preds = %bb + %2 = icmp ugt i32 %1, 999 ; <i1> [#uses=1] + %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=1] + br i1 %2, label %bb1.bb2_crit_edge, label %bb + +bb1.bb2_crit_edge: ; preds = %bb1 + %.lcssa = phi i32 [ %1, %bb1 ] ; <i32> [#uses=1] + br label %bb2 + +bb2: ; preds = %bb1.bb2_crit_edge, %entry + %x_addr.0.lcssa = phi i32 [ %.lcssa, %bb1.bb2_crit_edge ], [ %x, %entry ] ; <i32> [#uses=1] + ret i32 %x_addr.0.lcssa +} |