aboutsummaryrefslogtreecommitdiffstats
path: root/test/CodeGen/X86/pic.ll
blob: faaf73b18d9a25f10c5fb03de4371978e5e21e04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
; RUN: llc < %s -mcpu=generic -mtriple=i686-pc-linux-gnu -relocation-model=pic -asm-verbose=false -post-RA-scheduler=false | FileCheck %s -check-prefix=LINUX

@ptr = external global i32* 
@dst = external global i32 
@src = external global i32 

define void @test0() nounwind {
entry:
    store i32* @dst, i32** @ptr
    %tmp.s = load i32, i32* @src
    store i32 %tmp.s, i32* @dst
    ret void
    
; LINUX-LABEL:    test0:
; LINUX:	calll	.L0$pb
; LINUX-NEXT: .L0$pb:
; LINUX-NEXT:	popl
; LINUX:	addl	$_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L0$pb),
; LINUX:	movl	dst@GOT(%eax),
; LINUX:	movl	ptr@GOT(%eax),
; LINUX:	movl	src@GOT(%eax),
; LINUX:	ret
}

@ptr2 = global i32* null
@dst2 = global i32 0
@src2 = global i32 0

define void @test1() nounwind {
entry:
    store i32* @dst2, i32** @ptr2
    %tmp.s = load i32, i32* @src2
    store i32 %tmp.s, i32* @dst2
    ret void
    
; LINUX-LABEL: test1:
; LINUX:	calll	.L1$pb
; LINUX-NEXT: .L1$pb:
; LINUX-NEXT:	popl
; LINUX:	addl	$_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L1$pb), %eax
; LINUX:	movl	dst2@GOT(%eax),
; LINUX:	movl	ptr2@GOT(%eax),
; LINUX:	movl	src2@GOT(%eax),
; LINUX:	ret

}

declare i8* @malloc(i32)

define void @test2() nounwind {
entry:
    %ptr = call i8* @malloc(i32 40)
    ret void
; LINUX-LABEL: test2:
; LINUX: 	pushl	%ebx
; LINUX-NEXT: 	subl	$8, %esp
; LINUX-NEXT: 	calll	.L2$pb
; LINUX-NEXT: .L2$pb:
; LINUX-NEXT: 	popl	%ebx
; LINUX: 	addl	$_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L2$pb), %ebx
; LINUX: 	movl	$40, (%esp)
; LINUX: 	calll	malloc@PLT
; LINUX: 	addl	$8, %esp
; LINUX: 	popl	%ebx
; LINUX: 	ret
}

@pfoo = external global void(...)* 

define void @test3() nounwind {
entry:
    %tmp = call void(...)*(...)* @afoo()
    store void(...)* %tmp, void(...)** @pfoo
    %tmp1 = load void(...)*, void(...)** @pfoo
    call void(...)* %tmp1()
    ret void
; LINUX-LABEL: test3:
; LINUX: 	calll	.L3$pb
; LINUX-NEXT: .L3$pb:
; LINUX: 	popl
; LINUX: 	addl	$_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L3$pb), %[[REG3:e..]]
; LINUX: 	calll	afoo@PLT
; LINUX: 	movl	pfoo@GOT(%[[REG3]]),
; LINUX: 	calll	*
}

declare void(...)* @afoo(...)

define void @test4() nounwind {
entry:
    call void(...)* @foo()
    ret void
; LINUX-LABEL: test4:
; LINUX: calll	.L4$pb
; LINUX: popl	%ebx
; LINUX: addl	$_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L4$pb), %ebx
; LINUX: calll	foo@PLT
}

declare void @foo(...)


@ptr6 = internal global i32* null
@dst6 = internal global i32 0
@src6 = internal global i32 0

define void @test5() nounwind {
entry:
    store i32* @dst6, i32** @ptr6
    %tmp.s = load i32, i32* @src6
    store i32 %tmp.s, i32* @dst6
    ret void
    
; LINUX-LABEL: test5:
; LINUX: 	calll	.L5$pb
; LINUX-NEXT: .L5$pb:
; LINUX-NEXT: 	popl	%eax
; LINUX: 	addl	$_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L5$pb), %eax
; LINUX: 	leal	dst6@GOTOFF(%eax), %ecx
; LINUX: 	movl	%ecx, ptr6@GOTOFF(%eax)
; LINUX: 	movl	src6@GOTOFF(%eax), %ecx
; LINUX: 	movl	%ecx, dst6@GOTOFF(%eax)
; LINUX: 	ret
}


;; Test constant pool references.
define double @test6(i32 %a.u) nounwind {
entry:
    %tmp = icmp eq i32 %a.u,0
    %retval = select i1 %tmp, double 4.561230e+02, double 1.234560e+02
    ret double %retval

; LINUX: .LCPI6_0:

; LINUX-LABEL: test6:
; LINUX:    calll .L6$pb
; LINUX: .L6$pb:
; LINUX:    addl	$_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L6$pb), 
; LINUX:    fldl	.LCPI6_0@GOTOFF(
}


;; Test jump table references.
define void @test7(i32 %n.u) nounwind {
entry:
    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 ]
bb:
    tail call void(...)* @foo1()
    ret void
bb1:
    tail call void(...)* @foo2()
    ret void
bb2:
    tail call void(...)* @foo6()
    ret void
bb3:
    tail call void(...)* @foo3()
    ret void
bb4:
    tail call void(...)* @foo4()
    ret void
bb5:
    tail call void(...)* @foo5()
    ret void
bb6:
    tail call void(...)* @foo1()
    ret void
bb7:
    tail call void(...)* @foo2()
    ret void
bb8:
    tail call void(...)* @foo6()
    ret void
bb9:
    tail call void(...)* @foo3()
    ret void
bb10:
    tail call void(...)* @foo4()
    ret void
bb11:
    tail call void(...)* @foo5()
    ret void
bb12:
    tail call void(...)* @foo6()
    ret void
    
; LINUX-LABEL: test7:
; LINUX:   calll	.L7$pb
; LINUX: .L7$pb:
; LINUX:   addl	$_GLOBAL_OFFSET_TABLE_+(.L{{.*}}-.L7$pb),
; LINUX:   .LJTI7_0@GOTOFF(
; LINUX:   jmpl	*

; LINUX: .align 4
; LINUX-NEXT: .LJTI7_0:
; LINUX:   .long	 .LBB7_2@GOTOFF
; LINUX:   .long	 .LBB7_8@GOTOFF
; LINUX:   .long	 .LBB7_14@GOTOFF
; LINUX:   .long	 .LBB7_9@GOTOFF
; LINUX:   .long	 .LBB7_10@GOTOFF
}

declare void @foo1(...)
declare void @foo2(...)
declare void @foo6(...)
declare void @foo3(...)
declare void @foo4(...)
declare void @foo5(...)