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