4 ms·
As a long-time Asm programmer who has read a lot of compiler-generated code (usually for RE purposes), I completely sympathise with Linus - despite all the rese
by userbinator 12y ago
As a long-time Asm programmer who has read a lot of compiler-generated code (usually for RE purposes), I completely sympathise with Linus - despite all the research and improvements, compilers are still very stupid, and will routinely generate code that no sane human would. The widespread notion that compilers can almost always generate better (faster or smaller) code than a human is probably closer to myth than reality. The one thing that is certainly true is they can compile orders of magnitude faster than a human can, and that's usually the main reason for using them.
I think the x86-64 ABI is also partly to blame for this mess - IMHO it's far too complex (e.g. the "red zone") and makes it easy for these bizarre edge-case-bugs to occur.
"Spilling a constant" is something I've never seen before and I'd probably WTF the first time I saw it, but thinking about it more carefully, it might actually be a wise choice in some cases - x86-64 unfortunately allows very few instructions with 64-bit immediate values, and those few instructions are very long (opcode + 8-byte immediate), so it could make sense to store some constant in memory, on the stack, for a while and put it in a register when it's needed with some moves - 64-bit r/m move with 8-bit displacement is 3/4 bytes. Of course that's not what GCC is doing here; that last move instruction is 6 bytes alone (mov + mod/rm + disp32.)