On Mon, Jul 7, 2014 at 12:00 PM, Evgeny Stupachenko <evstu...@gmail.com> wrote: > Hi All, > > Currently GCC permanently reserves EBX as the GOT register. > > (config/i386/i386.c:4289) > > /* The PIC register, if it exists, is fixed. */ > j = PIC_OFFSET_TABLE_REGNUM; > if (j != INVALID_REGNUM) > fixed_regs[j] = call_used_regs[j] = 1; > > This leads to significant performance losses in PIC mode: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54232 > According to my measurements ~3% generally and up to 20% in inner loops. > > CLANG uses all registers for allocation and therefore now has > competitive advantage in 32bits PIC mode comparing to GCC. > This mode is used in all Android applications and therefore is > important for many compiler customers. > > There are at least 2 possible solutions. > > 1. > > While call expand emit SET_GOT -> EBX and MOV EBX -> some local register: LGOT > Prior to each call emit MOV LGOT -> EBX > Use LGOT as new GOT register for globals. > > 2. > > Set EBX as each CALL parameter. > Emit MOV EBX->LGOT in each call. > Use LGOT as new GOT register for globals. > > Do you have any comments, ideas?
Use some LCM algorithm for placing %ebx loads, similar to how we treat vzeroupper? Compute some simple IPA info on whether %ebx is provided/needed by callers/callees? Richard. > Thanks, > Evgeny