1 ; RUN: llc -mtriple=x86_64 -relocation-model=static < %s | FileCheck --check-prefixes=CHECK,STATIC %s
2 ; RUN: llc -mtriple=x86_64 -relocation-model=pic < %s | FileCheck --check-prefixes=CHECK,PIC %s
3 ; RUN: llc -mtriple=x86_64 -code-model=medium -relocation-model=static < %s | FileCheck --check-prefixes=CHECK,MSTATIC %s
4 ; RUN: llc -mtriple=x86_64 -code-model=medium -relocation-model=pic < %s | FileCheck --check-prefixes=CHECK,MPIC %s
6 @foo = internal global i32 0
8 define dso_local i64 @zero() #0 {
11 ; STATIC-NEXT: movl $foo, %eax
13 ; PIC-NEXT: leaq foo(%rip), %rax
15 ; MSTATIC-NEXT: movabsq $foo, %rax
17 ; MPIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rcx
18 ; MPIC-NEXT: movabsq $foo@GOTOFF, %rax
19 ; MPIC-NEXT: addq %rcx, %rax
21 ret i64 add (i64 ptrtoint (i32* @foo to i64), i64 0)
24 define dso_local i64 @one() #0 {
27 ; STATIC-NEXT: movl $foo+1, %eax
28 ; PIC-NEXT: leaq foo+1(%rip), %rax
29 ; MSTATIC-NEXT: movabsq $foo, %rax
30 ; MSTATIC-NEXT: incq %rax
31 ; MPIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
32 ; MPIC-NEXT: movabsq $foo@GOTOFF, %rcx
33 ; MPIC-NEXT: leaq 1(%rax,%rcx), %rax
35 ret i64 add (i64 ptrtoint (i32* @foo to i64), i64 1)
38 ;; Check we don't fold a large offset into leaq, otherwise
39 ;; the large r_addend can easily cause a relocation overflow.
40 define dso_local i64 @large() #0 {
43 ; STATIC-NEXT: movl $1701208431, %eax
44 ; STATIC-NEXT: leaq foo(%rax), %rax
45 ; PIC-NEXT: leaq foo(%rip), %rax
46 ; PIC-NEXT: addq $1701208431, %rax
47 ; MSTATIC-NEXT: movabsq $foo, %rax
48 ; MSTATIC-NEXT: addq $1701208431, %rax
50 ; MPIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
51 ; MPIC-NEXT: movabsq $foo@GOTOFF, %rcx
52 ; MPIC-NEXT: leaq 1701208431(%rax,%rcx), %rax
54 ret i64 add (i64 ptrtoint (i32* @foo to i64), i64 1701208431)
57 ;; Test we don't emit movl foo-1, %eax. ELF R_X86_64_32 does not allow
59 define dso_local i64 @neg_1() #0 {
62 ; STATIC-NEXT: leaq foo-1(%rip), %rax
63 ; PIC-NEXT: leaq foo-1(%rip), %rax
64 ; MSTATIC-NEXT: movabsq $foo, %rax
65 ; MSTATIC-NEXT: decq %rax
66 ; MPIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
67 ; MPIC-NEXT: movabsq $foo@GOTOFF, %rcx
68 ; MPIC-NEXT: leaq -1(%rax,%rcx), %rax
70 ret i64 add (i64 ptrtoint (i32* @foo to i64), i64 -1)
73 ;; Test we don't emit movl foo-2147483648, %eax. ELF R_X86_64_32 does not allow
75 define dso_local i64 @neg_0x80000000() #0 {
76 ; CHECK-LABEL: neg_0x80000000:
78 ; STATIC-NEXT: leaq foo-2147483648(%rip), %rax
79 ; PIC-NEXT: leaq foo-2147483648(%rip), %rax
80 ; MSTATIC-NEXT: movabsq $foo, %rax
81 ; MSTATIC-NEXT: addq $-2147483648, %rax
82 ; MPIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
83 ; MPIC-NEXT: movabsq $foo@GOTOFF, %rcx
84 ; MPIC-NEXT: leaq -2147483648(%rax,%rcx), %rax
86 ret i64 add (i64 ptrtoint (i32* @foo to i64), i64 -2147483648)
89 define dso_local i64 @neg_0x80000001() #0 {
90 ; CHECK-LABEL: neg_0x80000001:
92 ; STATIC-NEXT: movabsq $-2147483649, %rax
93 ; STATIC-NEXT: leaq foo(%rax), %rax
94 ; PIC-NEXT: leaq foo(%rip), %rcx
95 ; PIC-NEXT: movabsq $-2147483649, %rax
96 ; PIC-NEXT: addq %rcx, %rax
97 ; MSTATIC-NEXT: movabsq $-2147483649, %rcx
98 ; MSTATIC-NEXT: movabsq $foo, %rax
99 ; MSTATIC-NEXT: addq %rcx, %rax
100 ; MPIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
101 ; MPIC-NEXT: movabsq $foo@GOTOFF, %rcx
102 ; MPIC-NEXT: addq %rax, %rcx
103 ; MPIC-NEXT: movabsq $-2147483649, %rax
104 ; MPIC-NEXT: addq %rcx, %rax
106 ret i64 add (i64 ptrtoint (i32* @foo to i64), i64 -2147483649)
109 attributes #0 = { nounwind }