Denys Vlasenko writes:
> On Monday 08 October 2007 13:50, Heikki Linnakangas wrote:
> > While profiling a test case of exporting data from PostgreSQL, I noticed
> > that a lot of CPU time was spent in sprintf, formatting timestamps like
> > "2007-10-01 12:34". I could speed that up by an order of magnitude by
> > replacing the sprintf call with tailored code, but it occurred to me
> > that we could do the same in a more generic way in GCC.
>
> It is already done in gcc to some extent: for example, it
> replaces printf("message\n") with puts("Message").
>
> It's too far-fetched for my tastes. I think gcc should not do it.
> How gcc can know what printf() and puts() mean in *my* libc?
We can easily handle that with attributes. If a function is called
printf and has attribute printf then we can make the substitution.
Anway, we already do printf optimization:
p ()
{
printf ("Hello, World!\n");
}
results in
p:
movl $.LC0, %edi
call puts
ret
Andrew.