https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70731
Bug ID: 70731 Summary: With -Ofast, reorder floating-point and integer operands to minimize conversions Product: gcc Version: unknown Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: josh at joshtriplett dot org Target Milestone: --- [Not sure if this goes in the 'c' component or some appropriate optimizer component.] Given options like -ffast-math (and specifically, probably -fassociative-math), GCC should reorder operations with a series of floating-point and integer operands to minimize the number of conversions. For example, consider the following code (based loosely on a real optimization issue observed in zopfli, see http://roartindon.blogspot.com/2016/04/boosting-zopfli-performance.html): 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 on x86-64, with either -O3 or -Ofast, produces two cvtsi2sd instructions for the first, and just one cvtsi2sd for the second. (-Ofast does simplify some of the surrounding instructions, but not the conversion.) Given -fassociative-math, implied by -ffast-math and thus by -Ofast, I think GCC could reorder the additions in test1 to only do one conversion.