This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/37783] New: double (a+a)-(b+b) fetches constant 2.0, rather than using subtract
- From: "rrh at google dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 9 Oct 2008 16:36:58 -0000
- Subject: [Bug c/37783] New: double (a+a)-(b+b) fetches constant 2.0, rather than using subtract
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
the following code
double aaminusbb (const double a, const double b) { return (a+a)-(b+b); }
yields:
addsd %xmm0, %xmm0
mulsd .LC0(%rip), %xmm1
addsd %xmm1, %xmm0
ret
Where LC0 holds -2.0.
There's a perfectly good subtract instruction. Using it will avoid the memory
load to fetch the constant -2.0. Perhaps something like:
addsd %xmm0, %xmm0
addsd %xmm1, %xmm1
subsd %xmm1, %xmm0
ret
--
Summary: double (a+a)-(b+b) fetches constant 2.0, rather than
using subtract
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rrh at google dot com
GCC build triplet: i686-host_pc-linux-gnu
GCC host triplet: i686-host_pc-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37783