[Bug target/17622] New: Non-optimal code sequence for floating point "x=0; x=a*b;"
bangerth at dealii dot org
gcc-bugzilla@gcc.gnu.org
Wed Sep 22 21:34:00 GMT 2004
This would fix part of PR 17169:
Take this code:
--------------------
double a,b;
double foobar () {
double s = 0;
s += a * b;
return s;
}
--------------------
The compiler should realize that the two statements can be reduced
to "s=a*b". However, the compiler does so only when given -ffast-math.
Here's the assembler when compiled with -O3:
.LC1:
.long 0
.long 0
_Z6foobarv:
fldl b
fmull a
pushl %ebp
movl %esp, %ebp
popl %ebp
faddl .LC1
ret
And here with -O3 -ffast-math:
_Z6foobarv:
fldl b
fmull a
pushl %ebp
movl %esp, %ebp
popl %ebp
ret
I would argue that the addition of a zero can't change anything
if we have already determined overflow flags etc during the
multiplication immediately before.
(A point I'm not quite sure about, because I don't know the least
about cycle counts etc: wouldn't it be faster to use the
sequence "fldz ; faddp st,st(1)" rather than "faddl .LC1"? gcc2.95
used to create that sequence.)
W.
--
Summary: Non-optimal code sequence for floating point "x=0;
x=a*b;"
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: target
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bangerth at dealii dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17622
More information about the Gcc-bugs
mailing list