1 ; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 ; RUN: llc -max-registers-for-gc-values=4 -stop-after virtregrewriter < %s | FileCheck %s
4 target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-pc-linux-gnu"
7 declare dso_local void @"some_call"(ptr addrspace(1))
8 declare dso_local i32 @foo(i32, ptr addrspace(1), i32, i32, i32)
9 declare dso_local ptr @personality_function()
11 define ptr addrspace(1) @test_basic_invoke(ptr addrspace(1) %obj, ptr addrspace(1) %obj1)
12 ; CHECK-LABEL: name: test_basic_invoke
14 ; CHECK-NEXT: successors: %bb.1(0x7ffff800), %bb.3(0x00000800)
15 ; CHECK-NEXT: liveins: $rdi, $rsi
17 ; CHECK-NEXT: MOV64mr %stack.1, 1, $noreg, 0, $noreg, renamable $rdi :: (store (s64) into %stack.1)
18 ; CHECK-NEXT: MOV64mr %stack.0, 1, $noreg, 0, $noreg, killed renamable $rsi :: (store (s64) into %stack.0)
19 ; CHECK-NEXT: EH_LABEL <mcsymbol >
20 ; CHECK-NEXT: ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
21 ; CHECK-NEXT: STATEPOINT 0, 0, 1, @some_call, $rdi, 2, 0, 2, 0, 2, 5, 2, 0, 2, -1, 2, 0, 2, 0, 2, 0, 2, 2, 1, 8, %stack.0, 0, 1, 8, %stack.1, 0, 2, 0, 2, 2, 0, 0, 1, 1, csr_64, implicit-def $rsp, implicit-def $ssp :: (volatile load store (s64) on %stack.0), (volatile load store (s64) on %stack.1)
22 ; CHECK-NEXT: ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
23 ; CHECK-NEXT: EH_LABEL <mcsymbol >
24 ; CHECK-NEXT: JMP_1 %bb.1
26 ; CHECK-NEXT: bb.1.safepoint_normal_dest:
27 ; CHECK-NEXT: successors: %bb.2(0x80000000)
29 ; CHECK-NEXT: renamable $rax = MOV64rm %stack.1, 1, $noreg, 0, $noreg :: (load (s64) from %stack.1)
31 ; CHECK-NEXT: bb.2.normal_return:
32 ; CHECK-NEXT: liveins: $rax
34 ; CHECK-NEXT: RET 0, $rax
36 ; CHECK-NEXT: bb.3.exceptional_return (landing-pad):
37 ; CHECK-NEXT: liveins: $rax, $rdx
39 ; CHECK-NEXT: EH_LABEL <mcsymbol >
40 ; CHECK-NEXT: renamable $rax = MOV64rm %stack.0, 1, $noreg, 0, $noreg :: (load (s64) from %stack.0)
41 ; CHECK-NEXT: RET 0, $rax
42 gc "statepoint-example" personality ptr @"personality_function" {
44 %0 = invoke token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void (ptr addrspace(1))) @some_call, i32 1, i32 0, ptr addrspace(1) %obj, i32 0, i32 0) ["gc-live" (ptr addrspace(1) %obj, ptr addrspace(1) %obj1), "deopt" (i32 0, i32 -1, i32 0, i32 0, i32 0)]
45 to label %safepoint_normal_dest unwind label %exceptional_return
47 safepoint_normal_dest:
48 %obj.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %0, i32 0, i32 0)
49 %obj1.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %0, i32 1, i32 1)
50 br label %normal_return
53 ret ptr addrspace(1) %obj.relocated
56 %landing_pad = landingpad token
58 %obj.relocated1 = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %landing_pad, i32 0, i32 0)
59 %obj1.relocated1 = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %landing_pad, i32 1, i32 1)
60 ret ptr addrspace(1) %obj1.relocated1
63 define ptr addrspace(1) @test_invoke_same_val(i1 %cond, ptr addrspace(1) %val1, ptr addrspace(1) %val2, ptr addrspace(1) %val3)
64 ; CHECK-LABEL: name: test_invoke_same_val
66 ; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.3(0x40000000)
67 ; CHECK-NEXT: liveins: $edi, $rcx, $rdx, $rsi
69 ; CHECK-NEXT: renamable $r14 = COPY $rcx
70 ; CHECK-NEXT: renamable $r15 = COPY $rdx
71 ; CHECK-NEXT: renamable $ebx = COPY $edi
72 ; CHECK-NEXT: TEST8ri renamable $bl, 1, implicit-def $eflags
73 ; CHECK-NEXT: JCC_1 %bb.3, 4, implicit killed $eflags
74 ; CHECK-NEXT: JMP_1 %bb.1
76 ; CHECK-NEXT: bb.1.left:
77 ; CHECK-NEXT: successors: %bb.2(0x7ffff800), %bb.6(0x00000800)
78 ; CHECK-NEXT: liveins: $ebx, $rsi, $r15
80 ; CHECK-NEXT: MOV64mr %stack.0, 1, $noreg, 0, $noreg, renamable $rsi :: (store (s64) into %stack.0)
81 ; CHECK-NEXT: EH_LABEL <mcsymbol >
82 ; CHECK-NEXT: ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
83 ; CHECK-NEXT: $rdi = COPY killed renamable $rsi
84 ; CHECK-NEXT: renamable $r15 = STATEPOINT 0, 0, 1, @some_call, $rdi, 2, 0, 2, 0, 2, 0, 2, 2, killed renamable $r15(tied-def 0), 1, 8, %stack.0, 0, 2, 0, 2, 2, 0, 0, 1, 1, csr_64, implicit-def $rsp, implicit-def $ssp :: (volatile load store (s64) on %stack.0)
85 ; CHECK-NEXT: ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
86 ; CHECK-NEXT: EH_LABEL <mcsymbol >
87 ; CHECK-NEXT: JMP_1 %bb.2
89 ; CHECK-NEXT: bb.2.left.relocs:
90 ; CHECK-NEXT: successors: %bb.5(0x80000000)
91 ; CHECK-NEXT: liveins: $ebx, $r15
93 ; CHECK-NEXT: renamable $r14 = MOV64rm %stack.0, 1, $noreg, 0, $noreg :: (load (s64) from %stack.0)
94 ; CHECK-NEXT: JMP_1 %bb.5
96 ; CHECK-NEXT: bb.3.right:
97 ; CHECK-NEXT: successors: %bb.4(0x7ffff800), %bb.7(0x00000800)
98 ; CHECK-NEXT: liveins: $ebx, $rsi, $r14, $r15
100 ; CHECK-NEXT: MOV64mr %stack.0, 1, $noreg, 0, $noreg, killed renamable $r15 :: (store (s64) into %stack.0)
101 ; CHECK-NEXT: EH_LABEL <mcsymbol >
102 ; CHECK-NEXT: ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
103 ; CHECK-NEXT: $rdi = COPY killed renamable $rsi
104 ; CHECK-NEXT: renamable $r14 = STATEPOINT 0, 0, 1, @some_call, $rdi, 2, 0, 2, 0, 2, 0, 2, 2, killed renamable $r14(tied-def 0), 1, 8, %stack.0, 0, 2, 0, 2, 2, 0, 0, 1, 1, csr_64, implicit-def $rsp, implicit-def $ssp :: (volatile load store (s64) on %stack.0)
105 ; CHECK-NEXT: ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
106 ; CHECK-NEXT: EH_LABEL <mcsymbol >
107 ; CHECK-NEXT: JMP_1 %bb.4
109 ; CHECK-NEXT: bb.4.right.relocs:
110 ; CHECK-NEXT: successors: %bb.5(0x80000000)
111 ; CHECK-NEXT: liveins: $ebx, $r14
113 ; CHECK-NEXT: renamable $r15 = MOV64rm %stack.0, 1, $noreg, 0, $noreg :: (load (s64) from %stack.0)
115 ; CHECK-NEXT: bb.5.normal_return:
116 ; CHECK-NEXT: liveins: $ebx, $r14, $r15
118 ; CHECK-NEXT: TEST8ri renamable $bl, 1, implicit-def $eflags, implicit killed $ebx
119 ; CHECK-NEXT: renamable $r14 = CMOV64rr killed renamable $r14, killed renamable $r15, 4, implicit killed $eflags
120 ; CHECK-NEXT: $rax = COPY killed renamable $r14
121 ; CHECK-NEXT: RET 0, $rax
123 ; CHECK-NEXT: bb.6.exceptional_return.left (landing-pad):
124 ; CHECK-NEXT: liveins: $rax, $rdx
126 ; CHECK-NEXT: EH_LABEL <mcsymbol >
127 ; CHECK-NEXT: renamable $rax = MOV64rm %stack.0, 1, $noreg, 0, $noreg :: (load (s64) from %stack.0)
128 ; CHECK-NEXT: RET 0, $rax
130 ; CHECK-NEXT: bb.7.exceptional_return.right (landing-pad):
131 ; CHECK-NEXT: liveins: $rax, $rdx
133 ; CHECK-NEXT: EH_LABEL <mcsymbol >
134 ; CHECK-NEXT: renamable $rax = MOV64rm %stack.0, 1, $noreg, 0, $noreg :: (load (s64) from %stack.0)
135 ; CHECK-NEXT: RET 0, $rax
136 gc "statepoint-example" personality ptr @"personality_function" {
138 br i1 %cond, label %left, label %right
141 %sp1 = invoke token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void (ptr addrspace(1))) @some_call, i32 1, i32 0, ptr addrspace(1) %val1, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %val1, ptr addrspace(1) %val2)]
142 to label %left.relocs unwind label %exceptional_return.left
145 %val1.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %sp1, i32 0, i32 0)
146 %val2.relocated_left = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %sp1, i32 1, i32 1)
147 br label %normal_return
150 %sp2 = invoke token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void (ptr addrspace(1))) @some_call, i32 1, i32 0, ptr addrspace(1) %val1, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %val2, ptr addrspace(1) %val3)]
151 to label %right.relocs unwind label %exceptional_return.right
154 %val2.relocated_right = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %sp2, i32 0, i32 0)
155 %val3.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %sp2, i32 1, i32 1)
156 br label %normal_return
159 %a1 = phi ptr addrspace(1) [%val1.relocated, %left.relocs], [%val3.relocated, %right.relocs]
160 %a2 = phi ptr addrspace(1) [%val2.relocated_left, %left.relocs], [%val2.relocated_right, %right.relocs]
161 %ret = select i1 %cond, ptr addrspace(1) %a1, ptr addrspace(1) %a2
162 ret ptr addrspace(1) %ret
164 exceptional_return.left:
165 %landing_pad = landingpad token
167 %val1.relocated2 = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %landing_pad, i32 0, i32 0)
168 ret ptr addrspace(1) %val1.relocated2
170 exceptional_return.right:
171 %landing_pad1 = landingpad token
173 %val2.relocated3 = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %landing_pad1, i32 0, i32 0)
174 ret ptr addrspace(1) %val2.relocated3
177 define void @test_duplicate_ir_values() gc "statepoint-example" personality ptr @personality_function {
178 ; CHECK-LABEL: name: test_duplicate_ir_values
180 ; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.2(0x40000000)
182 ; CHECK-NEXT: renamable $rax = MOV64rm undef renamable $rax, 1, $noreg, 0, $noreg :: (load (s64) from `ptr addrspace(1) undef`, addrspace 1)
183 ; CHECK-NEXT: MOV64mr %stack.0, 1, $noreg, 0, $noreg, killed renamable $rax :: (store (s64) into %stack.0)
184 ; CHECK-NEXT: EH_LABEL <mcsymbol >
185 ; CHECK-NEXT: ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
186 ; CHECK-NEXT: STATEPOINT 1, 16, 5, undef renamable $rax, undef $edi, undef $rsi, undef $edx, undef $ecx, undef $r8d, 2, 0, 2, 0, 2, 0, 2, 1, 1, 8, %stack.0, 0, 2, 0, 2, 1, 0, 0, csr_64, implicit-def $rsp, implicit-def $ssp, implicit-def dead $eax :: (volatile load store (s64) on %stack.0)
187 ; CHECK-NEXT: ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
188 ; CHECK-NEXT: EH_LABEL <mcsymbol >
189 ; CHECK-NEXT: JMP_1 %bb.1
191 ; CHECK-NEXT: bb.1.normal_continue:
192 ; CHECK-NEXT: successors: {{$}}
194 ; CHECK-NEXT: renamable $rbx = MOV64rm %stack.0, 1, $noreg, 0, $noreg :: (load (s64) from %stack.0)
195 ; CHECK-NEXT: ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
196 ; CHECK-NEXT: $edi = MOV32ri 10
197 ; CHECK-NEXT: dead renamable $rbx = STATEPOINT 2882400000, 0, 1, target-flags(x86-plt) @__llvm_deoptimize, killed $edi, 2, 0, 2, 2, 2, 2, killed renamable $rbx, renamable $rbx, 2, 1, renamable $rbx(tied-def 0), 2, 0, 2, 1, 0, 0, csr_64, implicit-def $rsp, implicit-def $ssp
198 ; CHECK-NEXT: ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
200 ; CHECK-NEXT: bb.2.exceptional_return (landing-pad):
201 ; CHECK-NEXT: liveins: $rax, $rdx
203 ; CHECK-NEXT: EH_LABEL <mcsymbol >
204 ; CHECK-NEXT: renamable $rbx = MOV64rm %stack.0, 1, $noreg, 0, $noreg :: (load (s64) from %stack.0)
205 ; CHECK-NEXT: ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
206 ; CHECK-NEXT: $edi = MOV32ri -271
207 ; CHECK-NEXT: dead renamable $rbx = STATEPOINT 2882400000, 0, 1, target-flags(x86-plt) @__llvm_deoptimize, killed $edi, 2, 0, 2, 0, 2, 1, killed renamable $rbx, 2, 1, renamable $rbx(tied-def 0), 2, 0, 2, 1, 0, 0, csr_64, implicit-def $rsp, implicit-def $ssp
208 ; CHECK-NEXT: ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
210 %val1 = load ptr addrspace(1), ptr addrspace(1) undef, align 8
211 %val2 = load ptr addrspace(1), ptr addrspace(1) undef, align 8
212 %statepoint_token1 = invoke token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 1, i32 16, ptr nonnull elementtype(i32 (i32, ptr addrspace(1), i32, i32, i32)) @foo, i32 5, i32 0, i32 undef, ptr addrspace(1) undef, i32 undef, i32 undef, i32 undef, i32 0, i32 0) [ "deopt"(), "gc-live"(ptr addrspace(1) %val1, ptr addrspace(1) %val2) ]
213 to label %normal_continue unwind label %exceptional_return
215 normal_continue: ; preds = %entry
216 %val1.relocated1 = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token1, i32 0, i32 0) ; (%val1, %val1)
217 %val2.relocated1 = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token1, i32 1, i32 1) ; (%val2, %val2)
218 %safepoint_token2 = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr nonnull elementtype(void (i32)) @__llvm_deoptimize, i32 1, i32 2, i32 10, i32 0, i32 0) [ "deopt"(ptr addrspace(1) %val1.relocated1, ptr addrspace(1) %val2.relocated1), "gc-live"() ]
221 exceptional_return: ; preds = %entry
222 %lpad_token11090 = landingpad token
224 %val2.relocated2 = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %lpad_token11090, i32 1, i32 1) ; (%val2, %val2)
225 %safepoint_token3 = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr nonnull elementtype(void (i32)) @__llvm_deoptimize, i32 1, i32 0, i32 -271, i32 0, i32 0) [ "deopt"(ptr addrspace(1) %val2.relocated2), "gc-live"() ]
229 declare void @__llvm_deoptimize(i32)
230 declare token @llvm.experimental.gc.statepoint.p0(i64 immarg, i32 immarg, ptr, i32 immarg, i32 immarg, ...)
231 declare ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token, i32, i32)