https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70504
Bug ID: 70504 Summary: FLD, FLD, FXCH emitted instead of FLD, FLD in the needed order Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: b7.10110111 at gmail dot com Target Milestone: --- The following code demonstrates the bug: long double inl_scalbn(long double mant, long double exp) { long double result; asm("fscale" : "=&t"(result) : "%0"(mant), "u"(exp) ); return result; } With `-O3` option GCC generates the following assembly: inl_scalbn: fld TBYTE PTR [esp+4] fld TBYTE PTR [esp+16] fxch st(1) fscale fstp st(1) ret What's even stranger, I thought it was somehow related to order of function arguments, but if I switch `mant` and `exp`, the code just switches `fld` instructions instead of removing `fxch`. It's clear that in both cases the code could have just loaded the parameters in the correct order in the first place.