1 ; RUN: llc < %s -mcpu=generic -mtriple=i686-pc-linux-gnu -relocation-model=pic -asm-verbose=false -post-RA-scheduler=false -verify-machineinstrs | FileCheck %s -check-prefixes=CHECK,CHECK-I686
2 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-pc-linux-gnux32 -relocation-model=pic -asm-verbose=false -post-RA-scheduler=false -verify-machineinstrs | FileCheck %s -check-prefixes=CHECK,CHECK-X32
3 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-pc-linux-gnux32 -relocation-model=pic -asm-verbose=false -post-RA-scheduler=false -fast-isel -verify-machineinstrs | FileCheck %s -check-prefixes=CHECK,CHECK-X32
5 @ptr = external global ptr
6 @dst = external global i32
7 @src = external global i32
9 define void @test0() nounwind {
11 store ptr @dst, ptr @ptr
12 %tmp.s = load i32, ptr @src
13 store i32 %tmp.s, ptr @dst
17 ; CHECK-I686: calll .L0$pb
18 ; CHECK-I686-NEXT: .L0$pb:
19 ; CHECK-I686-NEXT: popl
20 ; CHECK-I686: addl $_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L0$pb),
21 ; CHECK-I686: movl dst@GOT(%eax),
22 ; CHECK-I686: movl ptr@GOT(%eax),
23 ; CHECK-I686: movl src@GOT(%eax),
25 ; CHECK-X32-DAG: movl dst@GOTPCREL(%rip),
26 ; CHECK-X32-DAG: movl ptr@GOTPCREL(%rip),
27 ; CHECK-X32-DAG: movl src@GOTPCREL(%rip),
31 @ptr2 = global ptr null
35 define void @test1() nounwind {
37 store ptr @dst2, ptr @ptr2
38 %tmp.s = load i32, ptr @src2
39 store i32 %tmp.s, ptr @dst2
43 ; CHECK-I686: calll .L1$pb
44 ; CHECK-I686-NEXT: .L1$pb:
45 ; CHECK-I686-NEXT: popl
46 ; CHECK-I686: addl $_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L1$pb), %eax
47 ; CHECK-I686: movl dst2@GOT(%eax),
48 ; CHECK-I686: movl ptr2@GOT(%eax),
49 ; CHECK-I686: movl src2@GOT(%eax),
51 ; CHECK-X32-DAG: movl dst2@GOTPCREL(%rip),
52 ; CHECK-X32-DAG: movl ptr2@GOTPCREL(%rip),
53 ; CHECK-X32-DAG: movl src2@GOTPCREL(%rip),
58 declare ptr @malloc(i32)
60 define void @test2() nounwind {
62 %ptr = call ptr @malloc(i32 40)
65 ; CHECK-I686: pushl %ebx
66 ; CHECK-I686-NEXT: subl $8, %esp
67 ; CHECK-I686-NEXT: calll .L2$pb
68 ; CHECK-I686-NEXT: .L2$pb:
69 ; CHECK-I686-NEXT: popl %ebx
70 ; CHECK-I686: addl $_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L2$pb), %ebx
71 ; CHECK-I686: movl $40, (%esp)
72 ; CHECK-I686: calll malloc@PLT
73 ; CHECK-I686: addl $8, %esp
74 ; CHECK-I686: popl %ebx
76 ; CHECK-X32: pushq %rax
77 ; CHECK-X32: movl $40, %edi
78 ; CHECK-X32: callq malloc@PLT
79 ; CHECK-X32: popq %rax
84 @pfoo = external global ptr
86 define void @test3() nounwind {
88 %tmp = call ptr(...) @afoo()
89 store ptr %tmp, ptr @pfoo
90 %tmp1 = load ptr, ptr @pfoo
91 call void(...) %tmp1()
94 ; CHECK-I686: calll .L3$pb
95 ; CHECK-I686-NEXT: .L3$pb:
97 ; CHECK-I686: addl $_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L3$pb), %[[REG3:e..]]
98 ; CHECK-I686: calll afoo@PLT
99 ; CHECK-I686: movl pfoo@GOT(%[[REG3]]),
100 ; CHECK-I686: calll *
101 ; CHECK-X32: callq afoo@PLT
102 ; CHECK-X32: movl pfoo@GOTPCREL(%rip),
106 declare ptr @afoo(...)
108 define void @test4() nounwind {
110 call void(...) @foo()
112 ; CHECK-LABEL: test4:
113 ; CHECK-I686: calll .L4$pb
114 ; CHECK-I686: popl %ebx
115 ; CHECK-I686: addl $_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L4$pb), %ebx
116 ; CHECK-I686: calll foo@PLT
117 ; CHECK-X32: callq foo@PLT
121 declare void @foo(...)
124 @ptr6 = internal global ptr null
125 @dst6 = internal global i32 0
126 @src6 = internal global i32 0
128 define void @test5() nounwind {
130 store ptr @dst6, ptr @ptr6
131 %tmp.s = load i32, ptr @src6
132 store i32 %tmp.s, ptr @dst6
135 ; CHECK-LABEL: test5:
136 ; CHECK-I686: calll .L5$pb
137 ; CHECK-I686-NEXT: .L5$pb:
138 ; CHECK-I686-NEXT: popl %eax
139 ; CHECK-I686: addl $_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L5$pb), %eax
140 ; CHECK-I686: leal dst6@GOTOFF(%eax), %ecx
141 ; CHECK-I686: movl %ecx, ptr6@GOTOFF(%eax)
142 ; CHECK-I686: movl src6@GOTOFF(%eax), %ecx
143 ; CHECK-I686: movl %ecx, dst6@GOTOFF(%eax)
145 ; CHECK-X32: leal dst6(%rip), %eax
146 ; CHECK-X32: movl %eax, ptr6(%rip)
147 ; CHECK-X32: movl src6(%rip), %eax
148 ; CHECK-X32: movl %eax, dst6(%rip)
153 ;; Test constant pool references.
154 define double @test6(i32 %a.u) nounwind {
156 %tmp = icmp eq i32 %a.u,0
157 %retval = select i1 %tmp, double 4.561230e+02, double 1.234560e+02
162 ; CHECK-LABEL: test6:
163 ; CHECK-I686: calll .L6$pb
164 ; CHECK-I686: .L6$pb:
165 ; CHECK-I686: addl $_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L6$pb),
166 ; CHECK-I686: fldl .LCPI6_0@GOTOFF(
167 ; CHECK-X32: .LCPI6_0(%rip),
171 ;; Test jump table references.
172 define void @test7(i32 %n.u) nounwind {
174 switch i32 %n.u, label %bb12 [i32 1, label %bb i32 2, label %bb6 i32 4, label %bb7 i32 5, label %bb8 i32 6, label %bb10 i32 7, label %bb1 i32 8, label %bb3 i32 9, label %bb4 i32 10, label %bb9 i32 11, label %bb2 i32 12, label %bb5 i32 13, label %bb11 ]
176 tail call void(...) @foo1()
179 tail call void(...) @foo2()
182 tail call void(...) @foo6()
185 tail call void(...) @foo3()
188 tail call void(...) @foo4()
191 tail call void(...) @foo5()
194 tail call void(...) @foo1()
197 tail call void(...) @foo2()
200 tail call void(...) @foo6()
203 tail call void(...) @foo3()
206 tail call void(...) @foo4()
209 tail call void(...) @foo5()
212 tail call void(...) @foo6()
215 ; CHECK-LABEL: test7:
216 ; CHECK-I686: calll .L7$pb
217 ; CHECK-I686: .L7$pb:
218 ; CHECK-I686: addl $_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L7$pb),
219 ; CHECK-I686: .LJTI7_0@GOTOFF(
221 ; CHECK-X32: leal .LJTI7_0(%rip), %eax
222 ; CHECK-X32: addl (%eax,%edi,4), %eax
223 ; CHECK-X32: jmpq *%rax
226 ; CHECK-NEXT: .LJTI7_0:
227 ; CHECK-I686: .long .LBB7_2@GOTOFF
228 ; CHECK-I686: .long .LBB7_8@GOTOFF
229 ; CHECK-I686: .long .LBB7_4@GOTOFF
230 ; CHECK-I686: .long .LBB7_6@GOTOFF
231 ; CHECK-I686: .long .LBB7_5@GOTOFF
232 ; CHECK-I686: .long .LBB7_8@GOTOFF
233 ; CHECK-I686: .long .LBB7_7@GOTOFF
234 ; CHECK-X32: .long .LBB7_3-.LJTI7_0
235 ; CHECK-X32: .long .LBB7_3-.LJTI7_0
236 ; CHECK-X32: .long .LBB7_12-.LJTI7_0
237 ; CHECK-X32: .long .LBB7_8-.LJTI7_0
238 ; CHECK-X32: .long .LBB7_12-.LJTI7_0
239 ; CHECK-X32: .long .LBB7_10-.LJTI7_0
240 ; CHECK-X32: .long .LBB7_8-.LJTI7_0
241 ; CHECK-X32: .long .LBB7_9-.LJTI7_0
242 ; CHECK-X32: .long .LBB7_10-.LJTI7_0
243 ; CHECK-X32: .long .LBB7_9-.LJTI7_0
244 ; CHECK-X32: .long .LBB7_12-.LJTI7_0
245 ; CHECK-X32: .long .LBB7_14-.LJTI7_0
246 ; CHECK-X32: .long .LBB7_14-.LJTI7_0
249 declare void @foo1(...)
250 declare void @foo2(...)
251 declare void @foo6(...)
252 declare void @foo3(...)
253 declare void @foo4(...)
254 declare void @foo5(...)
256 ;; Check TLS references
257 @tlsptrgd = thread_local global ptr null
258 @tlsdstgd = thread_local global i32 0
259 @tlssrcgd = thread_local global i32 0
260 @tlsptrld = thread_local(localdynamic) global ptr null
261 @tlsdstld = thread_local(localdynamic) global i32 0
262 @tlssrcld = thread_local(localdynamic) global i32 0
263 @tlsptrie = thread_local(initialexec) global ptr null
264 @tlsdstie = thread_local(initialexec) global i32 0
265 @tlssrcie = thread_local(initialexec) global i32 0
266 @tlsptrle = thread_local(localexec) global ptr null
267 @tlsdstle = thread_local(localexec) global i32 0
268 @tlssrcle = thread_local(localexec) global i32 0
270 define void @test8() nounwind {
272 store ptr @tlsdstgd, ptr @tlsptrgd
273 %tmp.s = load i32, ptr @tlssrcgd
274 store i32 %tmp.s, ptr @tlsdstgd
277 ; CHECK-LABEL: test8:
278 ; CHECK-I686: calll .L8$pb
279 ; CHECK-I686-NEXT: .L8$pb:
280 ; CHECK-I686-NEXT: popl
281 ; CHECK-I686: addl $_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L8$pb), %ebx
282 ; CHECK-I686-DAG: leal tlsdstgd@TLSGD(,%ebx), %eax
283 ; CHECK-I686-DAG: calll ___tls_get_addr@PLT
284 ; CHECK-I686-DAG: leal tlsptrgd@TLSGD(,%ebx), %eax
285 ; CHECK-I686-DAG: calll ___tls_get_addr@PLT
286 ; CHECK-I686-DAG: leal tlssrcgd@TLSGD(,%ebx), %eax
287 ; CHECK-I686-DAG: calll ___tls_get_addr@PLT
288 ; CHECK-X32-NOT: data16
289 ; CHECK-X32-DAG: leaq tlsdstgd@TLSGD(%rip), %rdi
290 ; CHECK-X32-DAG: callq __tls_get_addr@PLT
291 ; CHECK-X32-DAG: leaq tlsptrgd@TLSGD(%rip), %rdi
292 ; CHECK-X32-DAG: callq __tls_get_addr@PLT
293 ; CHECK-X32-DAG: leaq tlssrcgd@TLSGD(%rip), %rdi
294 ; CHECK-X32-DAG: callq __tls_get_addr@PLT
299 define void @test9() nounwind {
301 store ptr @tlsdstld, ptr @tlsptrld
302 %tmp.s = load i32, ptr @tlssrcld
303 store i32 %tmp.s, ptr @tlsdstld
306 ; CHECK-LABEL: test9:
307 ; CHECK-I686: calll .L9$pb
308 ; CHECK-I686-NEXT: .L9$pb:
309 ; CHECK-I686-NEXT: popl
310 ; CHECK-I686: addl $_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L9$pb), %ebx
311 ; CHECK-I686: leal tlsdstld@TLSLDM(%ebx), %eax
312 ; CHECK-X32: leaq tlsdstld@TLSLD(%rip), %rdi
313 ; CHECK-I686: calll ___tls_get_addr@PLT
314 ; CHECK-X32: callq __tls_get_addr@PLT
315 ; CHECK: leal tlsdstld@DTPOFF(
316 ; CHECK: movl {{%.*}}, tlsptrld@DTPOFF(
317 ; CHECK: movl tlssrcld@DTPOFF(
318 ; CHECK: movl {{%.*}}, tlsdstld@DTPOFF(
323 define void @test10() nounwind {
325 store ptr @tlsdstie, ptr @tlsptrie
326 %tmp.s = load i32, ptr @tlssrcie
327 store i32 %tmp.s, ptr @tlsdstie
330 ; CHECK-LABEL: test10:
331 ; CHECK-I686: calll .L10$pb
332 ; CHECK-I686-NEXT: .L10$pb:
333 ; CHECK-I686-NEXT: popl
334 ; CHECK-I686: addl $_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L10$pb),
335 ; CHECK-I686-DAG: movl tlsdstie@GOTNTPOFF(
336 ; CHECK-I686-DAG: movl %gs:0,
337 ; CHECK-X32-DAG: movl tlsdstie@GOTTPOFF(%rip),
338 ; CHECK-X32-DAG: movl %fs:0,
340 ; CHECK-X32: leal ({{%.*,%.*}}),
341 ; CHECK-I686: movl tlsptrie@GOTNTPOFF(
342 ; CHECK-X32: movl tlsptrie@GOTTPOFF(%rip),
343 ; CHECK-I686: movl {{%.*}}, %gs:(
344 ; CHECK-X32: movl {{%.*}}, ({{%.*,%.*}})
345 ; CHECK-I686: movl tlssrcie@GOTNTPOFF(
346 ; CHECK-X32: movl tlssrcie@GOTTPOFF(%rip),
347 ; CHECK-I686: movl %gs:(
348 ; CHECK-X32: movl ({{%.*,%.*}}),
349 ; CHECK-I686: movl {{%.*}}, %gs:(
350 ; CHECK-X32: movl {{%.*}}, ({{%.*,%.*}})
355 define void @test11() nounwind {
357 store ptr @tlsdstle, ptr @tlsptrle
358 %tmp.s = load i32, ptr @tlssrcle
359 store i32 %tmp.s, ptr @tlsdstle
362 ; CHECK-LABEL: test11:
363 ; CHECK-I686: movl %gs:0,
364 ; CHECK-X32: movl %fs:0,
365 ; CHECK-I686: leal tlsdstle@NTPOFF(
366 ; CHECK-X32: leal tlsdstle@TPOFF(
367 ; CHECK-I686: movl {{%.*}}, %gs:tlsptrle@NTPOFF
368 ; CHECK-X32: movl {{%.*}}, %fs:tlsptrle@TPOFF
369 ; CHECK-I686: movl %gs:tlssrcle@NTPOFF,
370 ; CHECK-X32: movl %fs:tlssrcle@TPOFF,
371 ; CHECK-I686: movl {{%.*}}, %gs:tlsdstle@NTPOFF
372 ; CHECK-X32: movl {{%.*}}, %fs:tlsdstle@TPOFF