File tree Expand file tree Collapse file tree 2 files changed +53
-3
lines changed Expand file tree Collapse file tree 2 files changed +53
-3
lines changed Original file line number Diff line number Diff line change @@ -56,13 +56,14 @@ void ADRRelaxationPass::runOnFunction(BinaryFunction &BF) {
5656 continue ;
5757 }
5858
59- // Don't relax adr if it points to the same function and it is not split
60- // and BF initial size is < 1MB.
59+ // Don't relax ADR if it points to the same function and is in the main
60+ // fragment and BF initial size is < 1MB.
6161 const unsigned OneMB = 0x100000 ;
6262 if (BF.getSize () < OneMB) {
6363 BinaryFunction *TargetBF = BC.getFunctionForSymbol (Symbol);
64- if (TargetBF == &BF && !BF .isSplit ())
64+ if (TargetBF == &BF && !BB .isSplit ())
6565 continue ;
66+
6667 // No relaxation needed if ADR references a basic block in the same
6768 // fragment.
6869 if (BinaryBasicBlock *TargetBB = BF.getBasicBlockForLabel (Symbol))
Original file line number Diff line number Diff line change 1+ ## Check th at llvm - bolt will not unnecessarily relax ADR instruction.
2+
3+ # RUN: llvm - mc - filetype=obj - triple aarch64 - unknown - unknown %s - o %t.o
4+ # RUN: %clang %cflags %t.o - o %t.exe - Wl ,- q - static
5+ # RUN: llvm - bolt %t.exe - o %t.bolt -- split - functions -- split - strategy=random2
6+ # RUN: llvm - objdump - d -- disassemble - symbols=_start %t.bolt | FileCheck %s
7+ # RUN: llvm - objdump - d -- disassemble - symbols=foo.cold. 0 %t.bolt \
8+ # RUN: | FileCheck -- check - prefix=CHECK - FOO %s
9+
10+ ## ADR below references its containing function th at is split. But ADR is always
11+ ## in the main fragment , thus there is no need to relax it.
12+ .text
13+ .globl _start
14+ .type _start , %function
15+ _start:
16+ # CHECK: <_start>:
17+ .cfi_startproc
18+ adr x1 , _start
19+ # CHECK - NOT : adrp
20+ # CHECK: adr
21+ cmp x1 , x11
22+ b.hi .L1
23+ mov x0 , # 0x0
24+ .L1:
25+ ret x30
26+ .cfi_endproc
27+ .size _start , . - _start
28+
29+
30+ ## In foo , ADR is in the split fragment but references the main one. Thus , it
31+ ## needs to be relaxed into ADRP + ADD .
32+ .globl foo
33+ .type foo , %function
34+ foo:
35+ .cfi_startproc
36+ cmp x1 , x11
37+ b.hi .L2
38+ mov x0 , # 0x0
39+ .L2:
40+ # CHECK - FOO: <foo.cold. 0 >:
41+ adr x1 , foo
42+ # CHECK - FOO: adrp
43+ # CHECK - FOO - NEXT: add
44+ ret x30
45+ .cfi_endproc
46+ .size foo , . - foo
47+
48+ ## Force relocation mode.
49+ .reloc 0 , R_AARCH64_NONE
You can’t perform that action at this time.
0 commit comments