xref: /llvm-project/llvm/test/Transforms/PlaceSafepoints/basic.ll (revision 1ceb79e2e075745f0c02aa8206227f60362e3743)
1; RUN: opt < %s -S -passes=place-safepoints | FileCheck %s
2
3; Do we insert a simple entry safepoint?
4define void @test_entry() gc "statepoint-example" {
5; CHECK-LABEL: @test_entry
6entry:
7; CHECK-LABEL: entry
8; CHECK: call void @do_safepoint
9  ret void
10}
11
12; On a non-gc function, we should NOT get an entry safepoint
13define void @test_negative() {
14; CHECK-LABEL: @test_negative
15entry:
16; CHECK-NOT: do_safepoint
17  ret void
18}
19
20; Do we insert a backedge safepoint in a statically
21; infinite loop?
22define void @test_backedge() gc "statepoint-example" {
23; CHECK-LABEL: test_backedge
24entry:
25; CHECK-LABEL: entry
26; This statepoint is technically not required, but we don't exploit that yet.
27; CHECK: call void @do_safepoint
28  br label %other
29
30; CHECK-LABEL: other
31; CHECK: call void @do_safepoint
32other:
33  br label %other
34}
35
36; Check that we remove an unreachable block rather than trying
37; to insert a backedge safepoint
38define void @test_unreachable() gc "statepoint-example" {
39; CHECK-LABEL: test_unreachable
40entry:
41; CHECK-LABEL: entry
42; CHECK: call void @do_safepoint
43  ret void
44
45; CHECK-NOT: other
46; CHECK-NOT: do_safepoint
47other:
48  br label %other
49}
50
51declare void @foo()
52
53declare zeroext i1 @i1_return_i1(i1)
54
55define i1 @test_call_with_result() gc "statepoint-example" {
56; CHECK-LABEL: test_call_with_result
57; This is checking that a statepoint_poll is inserted for a function
58; that takes 1 argument.
59; CHECK: call void @do_safepoint
60entry:
61  %call1 = tail call i1 (i1) @i1_return_i1(i1 false)
62  ret i1 %call1
63}
64
65; This function is inlined when inserting a poll.  To avoid recursive
66; issues, make sure we don't place safepoints in it.
67declare void @do_safepoint()
68define void @gc.safepoint_poll() {
69; CHECK-LABEL: gc.safepoint_poll
70; CHECK-LABEL: entry
71; CHECK-NEXT: do_safepoint
72; CHECK-NEXT: ret void
73entry:
74  call void @do_safepoint()
75  ret void
76}
77