http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49583
Summary: Reloading stack operands in the wrong order, so needs to insert fxch Product: gcc Version: 4.6.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: sgunder...@bigfoot.com Created attachment 24638 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24638 Minimal testcase Hi, It seems that when generating x87 code, GCC sometimes reloads items from the stack in the wrong order, and then goes to great lengths to swap them around. I have an example with six loads and six fxch instructions, but attached is a minimal example. Compiling with "gcc version 4.6.1 (Debian 4.6.1-1)" as follows: pannekake:~> gcc-4.6 -m32 -Wall -O2 -march=pentium3 -c fxch.c The odd sequence is around this: 41: d9 44 24 48 flds 0x48(%esp) 45: dd 5c 24 08 fstpl 0x8(%esp) 49: dd 14 24 fstl (%esp) 4c: d9 5c 24 10 fstps 0x10(%esp) 50: e8 fc ff ff ff call 51 <process+0x51> 55: d9 5c 24 1c fstps 0x1c(%esp) 59: d9 44 24 1c flds 0x1c(%esp) 5d: d9 44 24 10 flds 0x10(%esp) 61: d9 c9 fxch %st(1) 63: d9 1c b7 fstps (%edi,%esi,4) 66: 46 inc %esi 67: 39 ee cmp %ebp,%esi In particular, why did it use fstps immediately followed by flds of the same value? And if it really wants to reload (in my more complex example, it really needs to), why not just do the loads in the right order from the start instead of doing the fxch?