For the change to reorder the additions to add int-to-int and float-to-float to remove one conversion, I wonder if the compiler would do that itself if allowed to by -ffast-math (included in -Ofast)? Normally, the compiler cannot (even with -O3) perform changes that might change exact floating-point results.
EDIT: No, looks like gcc can't do this even with -ffast-math or -Ofast. Given the following C code:
double test1(int lbits, double lsym, int dbits, double dsym)
{
return lsym + lbits + dsym + dbits;
}
double test2(int lbits, double lsym, int dbits, double dsym)
{
return lbits + dbits + lsym + dsym;
}
GCC, with either -O3 or -Ofast, with or without -ffast-math, always produces two cvtsi2sd instructions for test1 and one cvtsi2sd instruction for test2.
Filed as a GCC feature request: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70731