public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/64960] New: Inefficient address pre-computation in PIC mode
@ 2015-02-06 13:56 enkovich.gnu at gmail dot com
2021-09-27 1:55 ` [Bug target/64960] [5 Regression] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: enkovich.gnu at gmail dot com @ 2015-02-06 13:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64960
Bug ID: 64960
Summary: Inefficient address pre-computation in PIC mode
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: enkovich.gnu at gmail dot com
After EBX was unfixed in i386 PIC target, we may see addresses of static
objects are loaded from GOT and placed to the stack for later usage. It allows
to reuse PIC register for other purposes. But in cases when PIC register is
still used (e.g. for calls) it may cause inefficiency in produced code. Here is
an example:
>cat test.c
void f (int);
int val1, *val2, val3;
int test (int max)
{
int i;
for (i = 0; i < max; i++)
{
val1 += val2[i];
f (val3);
}
}
>gcc test.c -O2 -fPIE -S -m32 -ffixed-esi -ffixed-edi -ffixed-edx
>cat test.s
...
movl val1@GOT(%ebx), %eax <-- may be removed
xorl %ebp, %ebp
movl %eax, 4(%esp) <-- may be removed
movl val2@GOT(%ebx), %eax <-- may be removed
movl %eax, 8(%esp) <-- may be removed
movl val3@GOT(%ebx), %eax <-- may be removed
movl %eax, 12(%esp) <-- may be removed
.L3:
movl 8(%esp), %eax <-- equal to movl val2@GOT(%ebx),
%eax
subl $12, %esp
movl (%eax), %ecx
movl 16(%esp), %eax <-- equal to movl val1@GOT(%ebx),
%eax
movl (%ecx,%ebp,4), %ecx
addl %ecx, (%eax)
addl $1, %ebp
movl 24(%esp), %eax <-- equal to movl val3@GOT(%ebx),
%eax
pushl (%eax)
call f@PLT
addl $16, %esp
cmpl %ebp, 32(%esp)
jne .L3
...
Also storing value on the stack doesn't benefit on static objects optimization
performed by linker which transforms movl <symbol>@GOT<PIC> into lea
instruction. It would be useful to avoid early address computation in case PIC
register is available at address usage.
Here is a code generated by GCC 4.9:
xorl %ebp, %ebp
.L2:
movl val2@GOT(%ebx), %eax
subl $12, %esp
movl (%eax), %ecx
movl val1@GOT(%ebx), %eax
movl (%ecx,%ebp,4), %ecx
addl %ecx, (%eax)
addl $1, %ebp
movl val3@GOT(%ebx), %eax
pushl (%eax)
call f@PLT
addl $16, %esp
cmpl 16(%esp), %ebp
jne .L2
Used gcc (GCC) 5.0.0 20150205 (experimental).
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug target/64960] [5 Regression] Inefficient address pre-computation in PIC mode
2015-02-06 13:56 [Bug rtl-optimization/64960] New: Inefficient address pre-computation in PIC mode enkovich.gnu at gmail dot com
@ 2021-09-27 1:55 ` pinskia at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-27 1:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64960
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Summary|Inefficient address |[5 Regression] Inefficient
|pre-computation in PIC mode |address pre-computation in
| |PIC mode
Resolution|--- |FIXED
Target Milestone|--- |5.0
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Was fixed during the developement of GCC 5. That is GCC 5.1.0 release did not
have this issue.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-27 1:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-06 13:56 [Bug rtl-optimization/64960] New: Inefficient address pre-computation in PIC mode enkovich.gnu at gmail dot com
2021-09-27 1:55 ` [Bug target/64960] [5 Regression] " pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).