AArch64: Optimize ADD relocations that resolve to zero
Implements an optimization for AArch64 ADD instructions that can be replaced by MOV or NOP.
Sivan Shani proposes an optimization for the AArch64 architecture in binutils, following the ‘ELF for the Arm 64-bit Architecture’ specification. The patch optimizes ADD instructions where the immediate value becomes zero after relocation, replacing them with MOV or NOP instructions for efficiency. The changes include updates to BFD and the ld testsuite.
In Details
This patch introduces an optimization to the AArch64 backend of binutils as recommended by the Arm64 ELF specification. Specifically, it targets ADD instructions where the immediate operand, after relocation, evaluates to zero. The optimization replaces ADD Rx, Ry, 0 with MOV Rx, Ry (for different registers) or ADD Rx, Rx, 0 with NOP (for same registers, 64-bit mode). Special care is taken for 32-bit operations and instructions involving the stack pointer (SP). The change affects bfd/elfxx-aarch64.c and adds new tests to ld/testsuite/ld-aarch64/.
- AArch64
- The 64-bit ARM architecture.
- ADD instruction
- A processor instruction that adds two operands together and stores the result in one of them.
- relocation
- The process of updating symbolic references in code to absolute or relocatable addresses after compilation.
- immediate
- A value that is a part of an instruction, rather than a reference to a memory location or register.
- MOV instruction
- A processor instruction that copies data from one location to another.
- NOP instruction
- No-Operation instruction. A processor instruction that does nothing.
- BFD
- Binary File Descriptor library, a GNU library that provides a common interface to various object file formats.
- ld
- The GNU linker, responsible for combining object files into an executable.
- ELF
- Executable and Linkable Format, a common standard file format for object files used in Unix-like systems.