[PATCH] Optimize stdarg functions

Zack Weinberg zack@codesourcery.com
Mon Sep 27 23:29:00 GMT 2004


Jakub Jelinek <jakub@redhat.com> writes:

> A new tree pass finds how many va_start invocations there are, if
> general and/or floating registers need to be saved and if all va_arg
> calls are executed at most once for each execution of associated
> va_start, determines also how many bytes of general/floating
> registers need to be saved.

Neat.  I know people who will be delighted when their static analysis
of GCC-generated assembly, looking for floating point instructions,
stops getting false positives on varargs prologues.

> E.g. open has the third argument provided only if O_CREAT is set,
> so usually the code will look like
> va_start (ap, flags); if (flags & O_CREAT) mode = va_arg (ap, mode_t); va_end (ap);
> or
> if (flags & O_CREAT) { va_start (ap, flags); mode = va_arg (ap, mode_t); va_end (ap); }
> For both these cases with this patch the prologue will be saving just one
> register.

In a case like this, could we not do even better, and generate code as
if 'mode' had been an ordinary third argument to the function?
(Assuming that the ABI does put it where an ordinary third argument
would have been - but usually this is true.)

zw



More information about the Gcc-patches mailing list