Skip to content

Commit 82564f4

Browse files
authored
[bolt][aarch64] test to reproduce the issue with ldr reg, literal
ldr reg, literal instruction is limited +/- 1MB range, emitCI put the constants by the end of function and the one is out of available range.
1 parent 8e6ef2d commit 82564f4

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// this test checks a load literal instructions changed to movk
2+
3+
// REQUIRES: system-linux
4+
5+
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
6+
7+
# RUN: link_fdata %s %t.o %t.fdata
8+
# RUN: %clang %cflags -pie %t.o -o %t.exe -Wl,-q -Wl,-z,relro -Wl,-z,now
9+
# RUN: llvm-bolt %t.exe -o %t.bolt -data %t.fdata \
10+
# RUN: --keep-nops --eliminate-unreachable=false
11+
# RUN: llvm-objdump --disassemble-symbols=foo %t.bolt | FileCheck %s
12+
13+
# CHECK: mov{{.*}} w19, #0
14+
# CHECK-NEXT: mov{{.*}} w22, #0
15+
# CHECK-NEXT: movk{{.*}} w23, #0, lsl #16
16+
# CHECK-NEXT: movk{{.*}} w23, #100
17+
# CHECK-NEXT: movk{{.*}} w24, #0, lsl #16
18+
# CHECK-NEXT: movk{{.*}} w24, #3
19+
20+
.text
21+
.align 4
22+
.local foo
23+
.type foo, %function
24+
foo:
25+
# FDATA: 1 main 0 1 foo 0 0 10
26+
stp x29, x30, [sp, #-32]!
27+
stp x19, x20, [sp, #16]
28+
mov x29, sp
29+
30+
mov w19, #0 // counter = 0
31+
mov w22, #0 // result = 0
32+
33+
ldr w23, .Llimit
34+
ldr w24, .LStep
35+
b .LStub
36+
37+
.LConstants:
38+
.Llimit: .word 100
39+
.LStep: .word 3
40+
41+
.LStub:
42+
.rep 0x100000
43+
nop
44+
.endr
45+
b .Lmain_loop
46+
47+
.Lmain_loop:
48+
madd w22, w19, w24, w22 // result += counter * increment
49+
50+
add w19, w19, #1
51+
cmp w19, w23
52+
b.lt .Lmain_loop
53+
54+
mov w0, w22
55+
56+
b .Lreturn_point
57+
58+
.Lreturn_point:
59+
ldp x19, x20, [sp, #16]
60+
ldp x29, x30, [sp], #32
61+
ret
62+
.size foo, .-foo
63+
64+
65+
.global main
66+
.type main, %function
67+
main:
68+
mov x0, #0
69+
bl foo
70+
mov x0, 0
71+
mov w8, #93
72+
svc #0
73+
74+
.size main, .-main

0 commit comments

Comments
 (0)