[all-commits] [llvm/llvm-project] 283c47: [lld][LoongArch] GOT indirection to PC relative op...

Zhaoxin Yang via All-commits all-commits at lists.llvm.org
Thu Jul 31 23:46:07 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 283c47b4c5231a1baf528355f7119a73ac168968
      https://github.com/llvm/llvm-project/commit/283c47b4c5231a1baf528355f7119a73ac168968
  Author: Zhaoxin Yang <yangzhaoxin at loongson.cn>
  Date:   2025-08-01 (Fri, 01 Aug 2025)

  Changed paths:
    M lld/ELF/Arch/LoongArch.cpp
    A lld/test/ELF/loongarch-pc-hi20-lo12-got.s
    M lld/test/ELF/loongarch-relax-pc-hi20-lo12.s

  Log Message:
  -----------
  [lld][LoongArch] GOT indirection to PC relative optimization (#123743)

In LoongArch, we try GOT indirection to PC relative optimization in
normal or medium code model, whether or not with R_LARCH_RELAX
relocation.

From:
* pcalau12i $a0, %got_pc_hi20(sym_got)
* ld.w/d $a0, $a0, %got_pc_lo12(sym_got)

To:
* pcalau12i $a0, %pc_hi20(sym)
* addi.w/d $a0, $a0, %pc_lo12(sym)

If the original code sequence can be relaxed into a single instruction
`pcaddi`, this patch will not be taken (see
https://github.com/llvm/llvm-project/pull/123566).
The optimization related to GOT is split into two locations because the
`relax()` function is part of an iteration fixed-point algorithm. We
should minimize it to achieve better linker performance.
    
Note: Althouth the optimization has been performed, the GOT entries
still exists, similarly to AArch64. Eliminating the entries will
increase code complexity.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list