FR: perform floating “x * 2” as “x + x”, always.
×2
s often occur in formulas (recent example), and I didn't go into details, but GCC seems to do it on sight, even at -O0
, nor does it require -ffast-math
.
Additions can be slightly cheaper in general, but more importantly, this often (with SSE in particular) saves on reading constant “2” from memory. Example of the potential effect where this also prevents the suboptimal decision to cache “2” by using a nonvolatile xmm6
:
Result on FPU is worse though, because the compiler stores t
in memory (i386/win32
). If it could work with t
entirely in FPU register, result would be better again. Even if it can’t, who cares about FPU anyway.