1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=x86_64 -relocation-model=static < %s | FileCheck --check-prefixes=STATIC %s
3 ; RUN: llc -mtriple=x86_64 -relocation-model=pic < %s | FileCheck --check-prefixes=PIC %s
4 ; RUN: llc -mtriple=x86_64 -code-model=medium -relocation-model=static < %s | FileCheck --check-prefixes=MSTATIC %s
5 ; RUN: llc -mtriple=x86_64 -code-model=medium -relocation-model=pic < %s | FileCheck --check-prefixes=MPIC %s
7 @foo = internal global i32 0
9 define dso_local i64 @zero() #0 {
11 ; STATIC: # %bb.0: # %entry
12 ; STATIC-NEXT: movl $foo, %eax
16 ; PIC: # %bb.0: # %entry
17 ; PIC-NEXT: leaq foo(%rip), %rax
20 ; MSTATIC-LABEL: zero:
21 ; MSTATIC: # %bb.0: # %entry
22 ; MSTATIC-NEXT: movabsq $foo, %rax
26 ; MPIC: # %bb.0: # %entry
27 ; MPIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rcx
28 ; MPIC-NEXT: movabsq $foo@GOTOFF, %rax
29 ; MPIC-NEXT: addq %rcx, %rax
32 ret i64 add (i64 ptrtoint (ptr @foo to i64), i64 0)
35 define dso_local i64 @one() #0 {
37 ; STATIC: # %bb.0: # %entry
38 ; STATIC-NEXT: movl $foo+1, %eax
42 ; PIC: # %bb.0: # %entry
43 ; PIC-NEXT: leaq foo+1(%rip), %rax
47 ; MSTATIC: # %bb.0: # %entry
48 ; MSTATIC-NEXT: movabsq $foo, %rax
49 ; MSTATIC-NEXT: incq %rax
53 ; MPIC: # %bb.0: # %entry
54 ; MPIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
55 ; MPIC-NEXT: movabsq $foo@GOTOFF, %rcx
56 ; MPIC-NEXT: leaq 1(%rax,%rcx), %rax
59 ret i64 add (i64 ptrtoint (ptr @foo to i64), i64 1)
62 ;; Check we don't fold a large offset into leaq, otherwise
63 ;; the large r_addend can easily cause a relocation overflow.
64 define dso_local i64 @large() #0 {
65 ; STATIC-LABEL: large:
66 ; STATIC: # %bb.0: # %entry
67 ; STATIC-NEXT: movl $1701208431, %eax # imm = 0x6566616F
68 ; STATIC-NEXT: leaq foo(%rax), %rax
72 ; PIC: # %bb.0: # %entry
73 ; PIC-NEXT: leaq foo(%rip), %rax
74 ; PIC-NEXT: addq $1701208431, %rax # imm = 0x6566616F
77 ; MSTATIC-LABEL: large:
78 ; MSTATIC: # %bb.0: # %entry
79 ; MSTATIC-NEXT: movabsq $foo, %rax
80 ; MSTATIC-NEXT: addq $1701208431, %rax # imm = 0x6566616F
84 ; MPIC: # %bb.0: # %entry
85 ; MPIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
86 ; MPIC-NEXT: movabsq $foo@GOTOFF, %rcx
87 ; MPIC-NEXT: leaq 1701208431(%rax,%rcx), %rax
90 ret i64 add (i64 ptrtoint (ptr @foo to i64), i64 1701208431)
93 ;; Test we don't emit movl foo-1, %eax. ELF R_X86_64_32 does not allow
95 define dso_local i64 @neg_1() #0 {
96 ; STATIC-LABEL: neg_1:
97 ; STATIC: # %bb.0: # %entry
98 ; STATIC-NEXT: leaq foo-1(%rip), %rax
102 ; PIC: # %bb.0: # %entry
103 ; PIC-NEXT: leaq foo-1(%rip), %rax
106 ; MSTATIC-LABEL: neg_1:
107 ; MSTATIC: # %bb.0: # %entry
108 ; MSTATIC-NEXT: movabsq $foo, %rax
109 ; MSTATIC-NEXT: decq %rax
113 ; MPIC: # %bb.0: # %entry
114 ; MPIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
115 ; MPIC-NEXT: movabsq $foo@GOTOFF, %rcx
116 ; MPIC-NEXT: leaq -1(%rax,%rcx), %rax
119 ret i64 add (i64 ptrtoint (ptr @foo to i64), i64 -1)
122 ;; Test we don't emit movl foo-2147483648, %eax. ELF R_X86_64_32 does not allow
124 define dso_local i64 @neg_0x80000000() #0 {
125 ; STATIC-LABEL: neg_0x80000000:
126 ; STATIC: # %bb.0: # %entry
127 ; STATIC-NEXT: leaq foo-2147483648(%rip), %rax
130 ; PIC-LABEL: neg_0x80000000:
131 ; PIC: # %bb.0: # %entry
132 ; PIC-NEXT: leaq foo-2147483648(%rip), %rax
135 ; MSTATIC-LABEL: neg_0x80000000:
136 ; MSTATIC: # %bb.0: # %entry
137 ; MSTATIC-NEXT: movabsq $foo, %rax
138 ; MSTATIC-NEXT: addq $-2147483648, %rax # imm = 0x80000000
141 ; MPIC-LABEL: neg_0x80000000:
142 ; MPIC: # %bb.0: # %entry
143 ; MPIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
144 ; MPIC-NEXT: movabsq $foo@GOTOFF, %rcx
145 ; MPIC-NEXT: leaq -2147483648(%rax,%rcx), %rax
148 ret i64 add (i64 ptrtoint (ptr @foo to i64), i64 -2147483648)
151 define dso_local i64 @neg_0x80000001() #0 {
152 ; STATIC-LABEL: neg_0x80000001:
153 ; STATIC: # %bb.0: # %entry
154 ; STATIC-NEXT: movabsq $-2147483649, %rax # imm = 0xFFFFFFFF7FFFFFFF
155 ; STATIC-NEXT: leaq foo(%rax), %rax
158 ; PIC-LABEL: neg_0x80000001:
159 ; PIC: # %bb.0: # %entry
160 ; PIC-NEXT: leaq foo(%rip), %rcx
161 ; PIC-NEXT: movabsq $-2147483649, %rax # imm = 0xFFFFFFFF7FFFFFFF
162 ; PIC-NEXT: addq %rcx, %rax
165 ; MSTATIC-LABEL: neg_0x80000001:
166 ; MSTATIC: # %bb.0: # %entry
167 ; MSTATIC-NEXT: movabsq $-2147483649, %rcx # imm = 0xFFFFFFFF7FFFFFFF
168 ; MSTATIC-NEXT: movabsq $foo, %rax
169 ; MSTATIC-NEXT: addq %rcx, %rax
172 ; MPIC-LABEL: neg_0x80000001:
173 ; MPIC: # %bb.0: # %entry
174 ; MPIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
175 ; MPIC-NEXT: movabsq $foo@GOTOFF, %rcx
176 ; MPIC-NEXT: addq %rax, %rcx
177 ; MPIC-NEXT: movabsq $-2147483649, %rax # imm = 0xFFFFFFFF7FFFFFFF
178 ; MPIC-NEXT: addq %rcx, %rax
181 ret i64 add (i64 ptrtoint (ptr @foo to i64), i64 -2147483649)
184 attributes #0 = { nounwind }