http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60962
Bug ID: 60962 Summary: b+(-2.f)*a generates multiplication instruction while b-2.f*a simplifies to addition&subtraction Product: gcc Version: 4.8.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: b7.10110111 at gmail dot com Created attachment 32681 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32681&action=edit A procedure compilable into assembly to reproduce the bug I've tried the following with -O3 -ffast-math -fassociative-math options (here all operands are floats): float lap0= point[-1]+point[1] + (-2.f)*point[0]; This part of code (compilable into assembly version attached) generates mulss/addss code (adding a constant in .rodata and reading it before) , which leads to 6% slowdown compared to this version: float lap0= point[-1]+point[1] - 2.f*point[0]; , which generates addss/subss code. My g++ version is g++ (Ubuntu 4.8.1-2ubuntu1~12.04) 4.8.1. The full command line is: g++ -O3 -ffast-math -fassociative-math -o test1.s -S -masm=intel test.cpp The problem also reproduces with g++ 4.5.