This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH: PR target/42601] Simplify code sequence to address static var with option -fpic
- From: Daniel Jacobowitz <dan at codesourcery dot com>
- To: Carrot Wei <carrot at google dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 4 Feb 2010 15:23:21 -0500
- Subject: Re: [PATCH: PR target/42601] Simplify code sequence to address static var with option -fpic
- References: <7587b291002031708h19ec653esed7cce3ac0c8a131@mail.gmail.com>
On Thu, Feb 04, 2010 at 09:08:35AM +0800, Carrot Wei wrote:
> Hi
>
> Current code sequence to address static variables with option -fpic is:
>
> ldr r3, .L2
> ldr r2, .L2+4
> .LPIC0:
> add r3, pc
> add r3, r3, r2
> ...
> .L2:
> .word _GLOBAL_OFFSET_TABLE_-(.LPIC0+4)
> .word .LANCHOR0(GOTOFF)
>
> With this patch it can be simplified as:
>
> ldr r3, .L2
> .LPIC0:
> add r3, pc
> ...
> .L2:
> .word .LANCHOR0-(.LPIC0+4)
This is clearly advantageous for your example. But the old code
generates a pointer to _GLOBAL_OFFSET_TABLE_ which can be reused (it
is probably live for most of the function), and a GOT-relative offset
to the variable (which is a constant pool entry that can be reused all
through the function). With your new code, the constant pool entry
can only be used to access the one anchor from the one spot.
Access from another spot requires another constant pool
entry.
I tried to come up with an example, but GCC currently does an awful
job; it will spill address computations to the stack instead of
rematerializing them. I couldn't get it to reuse the .LANCHOR0
pool entries, it just loads them once and then spills them.
So it's probably fine, but you may wish to look at the results on a
code base with large functions.
--
Daniel Jacobowitz
CodeSourcery