by JoshTriplett · 10y ago · 0 comments
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
I tested -ffast-math on clang and it won't reorder the additions to omit the conversion here.
I'm actually VERY wary of -ffast-math due to a bad experience some years ago where it just totally messed up my calculations and I couldn't avoid it messing up my calculations.
Even a 1ulp change (not accounting for the round down) in the final floating point comparison changed my compression results; so I'm not entirely confident about using -ffast-math without a huge test corpus -- but turning it on does improve the run time.