Question on i386 stack adjustment optimization
H. J. Lu
hjl@lucon.org
Tue Oct 18 19:05:00 GMT 2005
On Tue, Oct 18, 2005 at 07:10:52PM +0200, Jan Hubicka wrote:
> > 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?
>
I opened
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24419
We have 2 issues:
1. When prologue uses mov, memory shouldn't be clobbered. But
ix86_expand_prologue calls pro_epilogue_adjust_stack which clobbers
memory.
2. We convert stack pointer subtractions to push even when memory isn't
clobbered with patterns like
;; Convert esp subtractions to push.
(define_peephole2
[(match_scratch:SI 0 "r")
(parallel [(set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) (const_int
-4)))
(clobber (reg:CC FLAGS_REG))])]
"optimize_size || !TARGET_SUB_ESP_4"
[(clobber (match_dup 0))
(set (mem:SI (pre_dec:SI (reg:SI SP_REG))) (match_dup 0))])
I don't think we can do that since push will clobber memory.
H.J.
More information about the Gcc
mailing list