[lld] [lld][ELF] Fix a corner case of elf::getLoongArchPageDelta (PR #71907)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 19 05:25:38 PST 2023
heiher wrote:
What if we could get the page offset of current instruction and `pcalau12i` and record in unused immediate bit fields of `addi.d`/`lu32i.d` and `lu52i.d`. I think we can do it correct and these 4 instructions can be scheduled within the 16M(+/-8M) range. This is enough even for a larger basic block.
```asm
.L1:
pcalau12i $a1, 0 # R_LARCH_PCALA_HI20
addi.d $a0, $zero, A # R_LARCH_PCALA_LO12
lu32i.d $a0, B # R_LARCH_PCALA64_LO20
lu52i.d $a0, $a0, C # R_LARCH_PCALA64_HI12
add.d $a0, $a0, $a1
```
### A/B/C
page(4k) offset of current instruction and `pcalau12i`.
```
A = ((. >> 12) - (.L1 >> 12))
B = ((. >> 12) - (.L1 >> 12))
C = ((. >> 12) - (.L1 >> 12))
```
### PC
```
pcalau12i: PC = PC
addi.d: PC = PC - (A << 12)
lu32i.d: PC = PC - (B << 12)
lu52i.d: PC = PC - (C << 12)
```
### R_LARCH_*
```
DELTA = DEST - PC[63:12][000]
DELTA = DELTA + (DELTA[11] << 12)
DELTA = DELTA + (DELTA[31] << 32)
DELTA = DELTA - (DELTA[11] << 32)
R_LARCH_PCALA_HI20 = DELTA[31:12]
R_LARCH_PCALA_LO20 = DELTA[11:00]
R_LARCH_PCALA64_LO20 = DELTA[51:32]
R_LARCH_PCALA64_HI12 = DELTA[63:52]
```
https://github.com/llvm/llvm-project/pull/71907
More information about the llvm-commits
mailing list