This series of patches adds the PCREL_OPT optimization for the PC-relative support in the PowerPC compiler.
This optimization convert a single load or store of an external variable to use the R_PPC64_PCREL_OPT relocation. For example, a normal load of an external int variable (with -mcpu=future) would generate: PLD 9,ext_symbol@got@pcrel(0),1 LWA 10,0(9) That is, load the address of 'ext_symbol' into register 9. If 'ext_symbol' is defined in another module in the main program, and the current module is also in the main program, the linker will optimize this to: PADDI 9,ext_symbol(0),1 LWZ 10,0(9) If either the definition is not in the main program or we are linking for a shared library, the linker will create an address in the .got section and do a PLD of it: .section .got .got.ext_symbol: .quad ext_symbol .section .text PLD 9,.got.ext_symbol(0),1 LWZ 10,0(9) If the only use of the GOT address is a single load and store, we can optimize this further: PLD 9,ext_symbol@got@pcrel(0),1 .Lpcrel1: .reloc .Lpcrel1-8,R_PPC64_PCREL_OPT,.-(.Lpcrel1-8) LWZ 10,0(9) In this case, if the variable is defined in another module for the main program, and we are linking for the main program, the linker will transform this to: PLWZ 10,ext_symbol@pcrel(0),1 NOP There can be arbitrary instructions between the PLD and the LWA (or STW). For either loads or store, register 9 must only be used in the load or store, and must die at that point. For loads, there must be no reference to register 10 between the PLD and the LWZ. For a store, register 10 must be live at the PLD instruction, and must not be modified between the PLD and the STW instructions. There are 4 patches in this patch set. The first patch adds the basic PCREL_OPT for loads. The second patch adds support for loads involving sign, zero, and float extension to PCREL_OPT. The third patch adds support for optimizing stores with PCREL_OPT. The fourth patch is a series of tests to test whether the right number of PCREL_OPT relocations are generated. -- Michael Meissner, IBM IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA email: meiss...@linux.ibm.com, phone: +1 (978) 899-4797