> I modified the gcc i386 backend. Now my gcc optimizes function prologue > > movq %rbx, -16(%rsp) > movq %rbp, -8(%rsp) > subq $16, %rsp > > to > movq %rbx, -16(%rsp) > movq %rbp, -8(%rsp) > pushq %rax > pushq %rax > > The change was introduced by > > http://gcc.gnu.org/ml/gcc-patches/2000-04/msg00263.html > > I have a question. It is OK to turn stack pointer addition into > pop instructions with a scratch register. But I don't see how you can > turn stack pointer substraction into push instructions with a > scratch register since push will change the contents of the stack, > in addition to stack pointer.
Well, this change predated x86-64 and on x86 this is safe because data bellow stack pointer are volatile and can be modified anytime from signal handlers so the push instruction can't kill live data. However with red zone on x86-64 this is no longer so clear. It seems to me that it is safe too - for non-leaf functions we don't use red zone and for leaf function we have single adjustment in prologue and no live data in the area at that time... Do you see some misscompiations or something? Honza > > Thanks. > > > H.J.