public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/31263] New: Misoptimization of constant function expressions
@ 2007-03-19 13:52 o dot mangold at gmx dot de
2007-03-19 15:47 ` [Bug middle-end/31263] " pinskia at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: o dot mangold at gmx dot de @ 2007-03-19 13:52 UTC (permalink / raw)
To: gcc-bugs
I'm not sure, if this can be called a bug, but it is at least a really bad case
of poor optimization.
The following program calls the function 'Square' several times, either with
x=1000 or x=i*2-i-i+1000 (which is also 1000). The second version is executed
much FASTER. I see no reason, why this should be so. I tested it with gcc 4.1.1
and 4.1.2. The timings are more or less equal.
> gcc -O2 f_demo.c f_demo2.c -o f_demo
> time f_demo
real 0m1.537s
user 0m1.183s
sys 0m0.345s
> gcc -D VARIABLE_PAR -O2 f_demo.c f_demo2.c -o f_demo
> time f_demo
real 0m0.700s
user 0m0.368s
sys 0m0.329s
--- f_demo.c -----------------------------------------------------------
#include <stdlib.h>
double Square(double x);
#ifdef VARIABLE_PAR
#define PAR i*2-i-i+1000
#else
#define PAR 1000
#endif
int main()
{
const int iSize=50000000;
int i;
double *pdA=malloc(iSize*sizeof(double));
for(i=0;i<iSize;i++) {
pdA[i]=Square(PAR);
}
}
--- f_demo2.c ----------------------------------------------------
double Square(double x)
{
return x*x;
}
--
Summary: Misoptimization of constant function expressions
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: o dot mangold at gmx dot de
GCC build triplet: i386-redhat-linux
GCC host triplet: i386-pc-linux-gnu
GCC target triplet: i386-redhat-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31263
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug middle-end/31263] Misoptimization of constant function expressions
2007-03-19 13:52 [Bug c/31263] New: Misoptimization of constant function expressions o dot mangold at gmx dot de
@ 2007-03-19 15:47 ` pinskia at gcc dot gnu dot org
2007-03-19 16:47 ` rguenth at gcc dot gnu dot org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-03-19 15:47 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2007-03-19 15:47 -------
On the trunk, there is no difference in the assembly produced for PPC-darwin.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|c |middle-end
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31263
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug middle-end/31263] Misoptimization of constant function expressions
2007-03-19 13:52 [Bug c/31263] New: Misoptimization of constant function expressions o dot mangold at gmx dot de
2007-03-19 15:47 ` [Bug middle-end/31263] " pinskia at gcc dot gnu dot org
@ 2007-03-19 16:47 ` rguenth at gcc dot gnu dot org
2007-03-20 9:21 ` o dot mangold at gmx dot de
2007-04-03 5:33 ` [Bug target/31263] addressing modes are not selected correcly for x86 always pinskia at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-03-19 16:47 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from rguenth at gcc dot gnu dot org 2007-03-19 16:47 -------
On x86 different addressing modes and induction variables are used. Good:
.L2:
movq %r12, 8(%rsp)
addl $1, %ebp
movsd 8(%rsp), %xmm0
call Square
movsd %xmm0, (%rbx)
addq $8, %rbx
cmpl $50000000, %ebp
jne .L2
bad:
.L2:
movq %r12, 8(%rsp)
movsd 8(%rsp), %xmm0
call Square
movsd %xmm0, (%rbp,%rbx,8)
addq $1, %rbx
cmpq $50000000, %rbx
jne .L2
this is because we retain the complex expression until the last DOM run
after loop optimization (for 4.1.2 at least).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31263
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug middle-end/31263] Misoptimization of constant function expressions
2007-03-19 13:52 [Bug c/31263] New: Misoptimization of constant function expressions o dot mangold at gmx dot de
2007-03-19 15:47 ` [Bug middle-end/31263] " pinskia at gcc dot gnu dot org
2007-03-19 16:47 ` rguenth at gcc dot gnu dot org
@ 2007-03-20 9:21 ` o dot mangold at gmx dot de
2007-04-03 5:33 ` [Bug target/31263] addressing modes are not selected correcly for x86 always pinskia at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: o dot mangold at gmx dot de @ 2007-03-20 9:21 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from o dot mangold at gmx dot de 2007-03-20 09:21 -------
Maybe I should remark, that on my system the assembler output looks I little
different than yours.
Good:
.L2:
pushl %edi
fildl (%esp)
addl $4, %esp
fstpl (%esp)
call Square
fstpl (%esi,%ebx,8)
addl $1, %ebx
cmpl $50000000, %ebx
jne .L2
Bad:
.L2:
movl $0, (%esp)
movl $1083129856, 4(%esp)
call Square
fstpl -8(%esi,%ebx,8)
addl $1, %ebx
cmpl $50000001, %ebx
jne .L2
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31263
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/31263] addressing modes are not selected correcly for x86 always
2007-03-19 13:52 [Bug c/31263] New: Misoptimization of constant function expressions o dot mangold at gmx dot de
` (2 preceding siblings ...)
2007-03-20 9:21 ` o dot mangold at gmx dot de
@ 2007-04-03 5:33 ` pinskia at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-04-03 5:33 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from pinskia at gcc dot gnu dot org 2007-04-03 06:33 -------
To reproduce this on the trunk use "#define PAR i*2+1000-i-i" instead for the
complex one.
For PPC, VARIABLE_PAR is actually slower, as it tries to use (long unsigned
int) i * 8 as the index and PPC does not have that as an index mode.
And even the RTL optimizers are able to remove the i*2-i-i as we get:
((int) ((unsigned int) i + 1000) - i)
in final_cleanup so we were able to clean up one -i but not both on the tree
level.
The x86 issue is a target issue and I will report this other issue not saying
i*2+1000-i-i is 1000 as a differnet issue.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pinskia at gcc dot gnu dot
| |org
Component|middle-end |target
Keywords| |missed-optimization
Summary|Misoptimization of constant |addressing modes are not
|function expressions |selected correcly for x86
| |always
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31263
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-04-03 5:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-19 13:52 [Bug c/31263] New: Misoptimization of constant function expressions o dot mangold at gmx dot de
2007-03-19 15:47 ` [Bug middle-end/31263] " pinskia at gcc dot gnu dot org
2007-03-19 16:47 ` rguenth at gcc dot gnu dot org
2007-03-20 9:21 ` o dot mangold at gmx dot de
2007-04-03 5:33 ` [Bug target/31263] addressing modes are not selected correcly for x86 always pinskia at gcc dot gnu dot 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).