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
7 ; A simple counted loop with trivially known range
8 define void @test1(i32) gc "statepoint-example" {
11 ; CHECK: call void @do_safepoint
13 ; CHECK-NOT: call void @do_safepoint
20 %counter = phi i32 [ 0 , %entry ], [ %counter.inc , %loop ]
21 %counter.inc = add i32 %counter, 1
22 %counter.cmp = icmp slt i32 %counter.inc, 16
23 br i1 %counter.cmp, label %loop, label %exit
29 ; The same counted loop, but with an unknown early exit
30 define void @test2(i32) gc "statepoint-example" {
33 ; CHECK: call void @do_safepoint
35 ; CHECK-NOT: call void @do_safepoint
42 %counter = phi i32 [ 0 , %entry ], [ %counter.inc , %continue ]
43 %counter.inc = add i32 %counter, 1
44 %counter.cmp = icmp slt i32 %counter.inc, 16
45 br i1 undef, label %continue, label %exit
48 br i1 %counter.cmp, label %loop, label %exit
54 ; The range is a 8 bit value and we can't overflow
55 define void @test3(i8 %upper) gc "statepoint-example" {
58 ; CHECK: call void @do_safepoint
60 ; CHECK-NOT: call void @do_safepoint
67 %counter = phi i8 [ 0 , %entry ], [ %counter.inc , %loop ]
68 %counter.inc = add nsw i8 %counter, 1
69 %counter.cmp = icmp slt i8 %counter.inc, %upper
70 br i1 %counter.cmp, label %loop, label %exit
76 ; The range is a 64 bit value
77 define void @test4(i64 %upper) gc "statepoint-example" {
80 ; CHECK: call void @do_safepoint
82 ; CHECK: call void @do_safepoint
85 ; COUNTED-64-LABEL: test4
86 ; COUNTED-64-LABEL: entry
87 ; COUNTED-64: call void @do_safepoint
88 ; COUNTED-64-LABEL: loop
89 ; COUNTED-64-NOT: call void @do_safepoint
90 ; COUNTED-64-LABEL: exit
96 %counter = phi i64 [ 0 , %entry ], [ %counter.inc , %loop ]
97 %counter.inc = add i64 %counter, 1
98 %counter.cmp = icmp slt i64 %counter.inc, %upper
99 br i1 %counter.cmp, label %loop, label %exit
105 ; This loop can run infinitely (for %upper == INT64_MAX) so it needs a
107 define void @test5(i64 %upper) gc "statepoint-example" {
110 ; CHECK: call void @do_safepoint
112 ; CHECK: call void @do_safepoint
115 ; COUNTED-64-LABEL: test5
116 ; COUNTED-64-LABEL: entry
117 ; COUNTED-64: call void @do_safepoint
118 ; COUNTED-64-LABEL: loop
119 ; COUNTED-64: call void @do_safepoint
120 ; COUNTED-64-LABEL: exit
126 %counter = phi i64 [ 0 , %entry ], [ %counter.inc , %loop ]
127 %counter.inc = add i64 %counter, 1
128 %counter.cmp = icmp sle i64 %counter.inc, %upper
129 br i1 %counter.cmp, label %loop, label %exit
136 ; This function is inlined when inserting a poll.
137 declare void @do_safepoint()
138 define void @gc.safepoint_poll() {
139 ; CHECK-LABEL: gc.safepoint_poll
141 call void @do_safepoint()