xref: /aosp_15_r20/external/llvm/test/Verifier/statepoint.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt -S %s -verify | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Workerdeclare void @use(...)
4*9880d681SAndroid Build Coastguard Workerdeclare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token, i32, i32)
5*9880d681SAndroid Build Coastguard Workerdeclare i64 addrspace(1)* @llvm.experimental.gc.relocate.p1i64(token, i32, i32)
6*9880d681SAndroid Build Coastguard Workerdeclare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
7*9880d681SAndroid Build Coastguard Workerdeclare i32 @"personality_function"()
8*9880d681SAndroid Build Coastguard Worker
9*9880d681SAndroid Build Coastguard Worker;; Basic usage
10*9880d681SAndroid Build Coastguard Workerdefine i64 addrspace(1)* @test1(i8 addrspace(1)* %arg) gc "statepoint-example" {
11*9880d681SAndroid Build Coastguard Workerentry:
12*9880d681SAndroid Build Coastguard Worker  %cast = bitcast i8 addrspace(1)* %arg to i64 addrspace(1)*
13*9880d681SAndroid Build Coastguard Worker  %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 0, i32 0, i32 10, i32 0, i8 addrspace(1)* %arg, i64 addrspace(1)* %cast, i8 addrspace(1)* %arg, i8 addrspace(1)* %arg)
14*9880d681SAndroid Build Coastguard Worker  %reloc = call i64 addrspace(1)* @llvm.experimental.gc.relocate.p1i64(token %safepoint_token, i32 12, i32 13)
15*9880d681SAndroid Build Coastguard Worker  ;; It is perfectly legal to relocate the same value multiple times...
16*9880d681SAndroid Build Coastguard Worker  %reloc2 = call i64 addrspace(1)* @llvm.experimental.gc.relocate.p1i64(token %safepoint_token, i32 12, i32 13)
17*9880d681SAndroid Build Coastguard Worker  %reloc3 = call i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %safepoint_token, i32 13, i32 12)
18*9880d681SAndroid Build Coastguard Worker  ret i64 addrspace(1)* %reloc
19*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test1
20*9880d681SAndroid Build Coastguard Worker; CHECK: statepoint
21*9880d681SAndroid Build Coastguard Worker; CHECK: gc.relocate
22*9880d681SAndroid Build Coastguard Worker; CHECK: gc.relocate
23*9880d681SAndroid Build Coastguard Worker; CHECK: gc.relocate
24*9880d681SAndroid Build Coastguard Worker; CHECK: ret i64 addrspace(1)* %reloc
25*9880d681SAndroid Build Coastguard Worker}
26*9880d681SAndroid Build Coastguard Worker
27*9880d681SAndroid Build Coastguard Worker; This test catches two cases where the verifier was too strict:
28*9880d681SAndroid Build Coastguard Worker; 1) A base doesn't need to be relocated if it's never used again
29*9880d681SAndroid Build Coastguard Worker; 2) A value can be replaced by one which is known equal.  This
30*9880d681SAndroid Build Coastguard Worker; means a potentially derived pointer can be known base and that
31*9880d681SAndroid Build Coastguard Worker; we can't check that derived pointer are never bases.
32*9880d681SAndroid Build Coastguard Workerdefine void @test2(i8 addrspace(1)* %arg, i64 addrspace(1)* %arg2) gc "statepoint-example" {
33*9880d681SAndroid Build Coastguard Workerentry:
34*9880d681SAndroid Build Coastguard Worker  %cast = bitcast i8 addrspace(1)* %arg to i64 addrspace(1)*
35*9880d681SAndroid Build Coastguard Worker  %c = icmp eq i64 addrspace(1)* %cast,  %arg2
36*9880d681SAndroid Build Coastguard Worker  br i1 %c, label %equal, label %notequal
37*9880d681SAndroid Build Coastguard Worker
38*9880d681SAndroid Build Coastguard Workernotequal:
39*9880d681SAndroid Build Coastguard Worker  ret void
40*9880d681SAndroid Build Coastguard Worker
41*9880d681SAndroid Build Coastguard Workerequal:
42*9880d681SAndroid Build Coastguard Worker  %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 0, i32 0, i32 10, i32 0, i8 addrspace(1)* %arg, i64 addrspace(1)* %cast, i8 addrspace(1)* %arg, i8 addrspace(1)* %arg)
43*9880d681SAndroid Build Coastguard Worker  %reloc = call i64 addrspace(1)* @llvm.experimental.gc.relocate.p1i64(token %safepoint_token, i32 12, i32 13)
44*9880d681SAndroid Build Coastguard Worker  call void undef(i64 addrspace(1)* %reloc)
45*9880d681SAndroid Build Coastguard Worker  ret void
46*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test2
47*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: equal
48*9880d681SAndroid Build Coastguard Worker; CHECK: statepoint
49*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %reloc = call
50*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: call
51*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret voi
52*9880d681SAndroid Build Coastguard Worker}
53*9880d681SAndroid Build Coastguard Worker
54*9880d681SAndroid Build Coastguard Worker; Basic test for invoke statepoints
55*9880d681SAndroid Build Coastguard Workerdefine i8 addrspace(1)* @test3(i8 addrspace(1)* %obj, i8 addrspace(1)* %obj1) gc "statepoint-example" personality i32 ()* @"personality_function" {
56*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test3
57*9880d681SAndroid Build Coastguard Workerentry:
58*9880d681SAndroid Build Coastguard Worker  ; CHECK-LABEL: entry
59*9880d681SAndroid Build Coastguard Worker  ; CHECK: statepoint
60*9880d681SAndroid Build Coastguard Worker  %0 = invoke token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0, i8 addrspace(1)* %obj, i8 addrspace(1)* %obj1)
61*9880d681SAndroid Build Coastguard Worker          to label %normal_dest unwind label %exceptional_return
62*9880d681SAndroid Build Coastguard Worker
63*9880d681SAndroid Build Coastguard Workernormal_dest:
64*9880d681SAndroid Build Coastguard Worker  ; CHECK-LABEL: normal_dest:
65*9880d681SAndroid Build Coastguard Worker  ; CHECK: gc.relocate
66*9880d681SAndroid Build Coastguard Worker  ; CHECK: gc.relocate
67*9880d681SAndroid Build Coastguard Worker  ; CHECK: ret
68*9880d681SAndroid Build Coastguard Worker  %obj.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %0, i32 12, i32 12)
69*9880d681SAndroid Build Coastguard Worker  %obj1.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %0, i32 12, i32 12)
70*9880d681SAndroid Build Coastguard Worker  ret i8 addrspace(1)* %obj.relocated
71*9880d681SAndroid Build Coastguard Worker
72*9880d681SAndroid Build Coastguard Workerexceptional_return:
73*9880d681SAndroid Build Coastguard Worker  ; CHECK-LABEL: exceptional_return
74*9880d681SAndroid Build Coastguard Worker  ; CHECK: gc.relocate
75*9880d681SAndroid Build Coastguard Worker  ; CHECK: gc.relocate
76*9880d681SAndroid Build Coastguard Worker  %landing_pad = landingpad token
77*9880d681SAndroid Build Coastguard Worker          cleanup
78*9880d681SAndroid Build Coastguard Worker  %obj.relocated1 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %landing_pad, i32 12, i32 12)
79*9880d681SAndroid Build Coastguard Worker  %obj1.relocated1 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %landing_pad, i32 12, i32 12)
80*9880d681SAndroid Build Coastguard Worker  ret i8 addrspace(1)* %obj1.relocated1
81*9880d681SAndroid Build Coastguard Worker}
82