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" {
13 ; CHECK-NOT: statepoint
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
28 ; The same counted loop, but with an unknown early exit
29 define void @test2(i32) gc "statepoint-example" {
34 ; CHECK-NOT: statepoint
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
46 br i1 %counter.cmp, label %loop, label %exit
52 ; The range is a 8 bit value and we can't overflow
53 define void @test3(i8 %upper) gc "statepoint-example" {
58 ; CHECK-NOT: statepoint
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
73 ; The range is a 64 bit value
74 define void @test4(i64 %upper) gc "statepoint-example" {
81 ; COUNTED-64-LABEL: test4
82 ; COUNTED-64-LABEL: entry
83 ; COUNTED-64: statepoint
84 ; COUNTED-64-LABEL: loop
85 ; COUNTED-64-NOT: statepoint
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
100 ; This loop can run infinitely (for %upper == INT64_MAX) so it needs a
102 define void @test5(i64 %upper) gc "statepoint-example" {
109 ; COUNTED-64-LABEL: test5
110 ; COUNTED-64-LABEL: entry
111 ; COUNTED-64: statepoint
112 ; COUNTED-64-LABEL: loop
113 ; COUNTED-64: statepoint
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
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
134 call void @do_safepoint()