9121e92896c8379c66c0e75bf525a2c43c5d5fc5
[oota-llvm.git] / test / Transforms / PlaceSafepoints / finite-loops.ll
1 ; Tests to ensure that we are not placing backedge safepoints in
2 ; loops which are clearly finite.
3 ;; RUN: opt %s -place-safepoints -spp-counted-loop-trip-width=32 -S | FileCheck %s
4 ;; RUN: opt %s -place-safepoints -spp-counted-loop-trip-width=64 -S | FileCheck %s -check-prefix=COUNTED-64
5
6
7 ; A simple counted loop with trivially known range
8 define void @test1(i32) gc "statepoint-example" {
9 ; CHECK-LABEL: test1
10 ; CHECK-LABEL: entry
11 ; CHECK: statepoint
12 ; CHECK-LABEL: loop
13 ; CHECK-NOT: statepoint
14
15 entry:
16   br label %loop
17
18 loop:
19   %counter = phi i32 [ 0 , %entry ], [ %counter.inc , %loop ]
20   %counter.inc = add i32 %counter, 1
21   %counter.cmp = icmp slt i32 %counter.inc, 16
22   br i1 %counter.cmp, label %loop, label %exit
23
24 exit:
25   ret void
26 }
27
28 ; The same counted loop, but with an unknown early exit
29 define void @test2(i32) gc "statepoint-example" {
30 ; CHECK-LABEL: test2
31 ; CHECK-LABEL: entry
32 ; CHECK: statepoint
33 ; CHECK-LABEL: loop
34 ; CHECK-NOT: statepoint
35
36 entry:
37   br label %loop
38
39 loop:
40   %counter = phi i32 [ 0 , %entry ], [ %counter.inc , %continue ]
41   %counter.inc = add i32 %counter, 1
42   %counter.cmp = icmp slt i32 %counter.inc, 16
43   br i1 undef, label %continue, label %exit
44
45 continue:
46   br i1 %counter.cmp, label %loop, label %exit
47
48 exit:
49   ret void
50 }
51
52 ; The range is a 8 bit value and we can't overflow
53 define void @test3(i8 %upper) gc "statepoint-example" {
54 ; CHECK-LABEL: test3
55 ; CHECK-LABEL: entry
56 ; CHECK: statepoint
57 ; CHECK-LABEL: loop
58 ; CHECK-NOT: statepoint
59
60 entry:
61   br label %loop
62
63 loop:
64   %counter = phi i8 [ 0 , %entry ], [ %counter.inc , %loop ]
65   %counter.inc = add nsw i8 %counter, 1
66   %counter.cmp = icmp slt i8 %counter.inc, %upper
67   br i1 %counter.cmp, label %loop, label %exit
68
69 exit:
70   ret void
71 }
72
73 ; The range is a 64 bit value
74 define void @test4(i64 %upper) gc "statepoint-example" {
75 ; CHECK-LABEL: test4
76 ; CHECK-LABEL: entry
77 ; CHECK: statepoint
78 ; CHECK-LABEL: loop
79 ; CHECK: statepoint
80
81 ; COUNTED-64-LABEL: test4
82 ; COUNTED-64-LABEL: entry
83 ; COUNTED-64: statepoint
84 ; COUNTED-64-LABEL: loop
85 ; COUNTED-64-NOT: statepoint
86
87 entry:
88   br label %loop
89
90 loop:
91   %counter = phi i64 [ 0 , %entry ], [ %counter.inc , %loop ]
92   %counter.inc = add i64 %counter, 1
93   %counter.cmp = icmp slt i64 %counter.inc, %upper
94   br i1 %counter.cmp, label %loop, label %exit
95
96 exit:
97   ret void
98 }
99
100 ; This loop can run infinitely (for %upper == INT64_MAX) so it needs a
101 ; safepoint.
102 define void @test5(i64 %upper) gc "statepoint-example" {
103 ; CHECK-LABEL: test5
104 ; CHECK-LABEL: entry
105 ; CHECK: statepoint
106 ; CHECK-LABEL: loop
107 ; CHECK: statepoint
108
109 ; COUNTED-64-LABEL: test5
110 ; COUNTED-64-LABEL: entry
111 ; COUNTED-64: statepoint
112 ; COUNTED-64-LABEL: loop
113 ; COUNTED-64: statepoint
114
115 entry:
116   br label %loop
117
118 loop:
119   %counter = phi i64 [ 0 , %entry ], [ %counter.inc , %loop ]
120   %counter.inc = add i64 %counter, 1
121   %counter.cmp = icmp sle i64 %counter.inc, %upper
122   br i1 %counter.cmp, label %loop, label %exit
123
124 exit:
125   ret void
126 }
127
128
129 ; This function is inlined when inserting a poll.
130 declare void @do_safepoint()
131 define void @gc.safepoint_poll() {
132 ; CHECK-LABEL: gc.safepoint_poll
133 entry:
134   call void @do_safepoint()
135   ret void
136 }