This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Move printf and fprintf builtins to middle-end.
On Mon, Jul 21, 2003 at 11:21:46AM -0400, Kaveh R. Ghazi wrote:
> #include <stdio.h>
> int main()
> {
> #ifdef OPT
> printf ("error1 message xyz at f.c:9\n");
> printf ("error2 message xyz at f.c:10\n");
> printf ("error3 message xyz at f.c:11\n");
> #else
> printf ("error1 message xyz at %s:%d\n", __FILE__, __LINE__);
> printf ("error2 message xyz at %s:%d\n", __FILE__, __LINE__);
> printf ("error3 message xyz at %s:%d\n", __FILE__, __LINE__);
> #endif
> return 0;
> }
>
> On sparc-sun-solaris2.7, with "-m64 -O2" with the "size" program I
> normally get 3134 bytes. When I compile with -DOPT, I get 3048 for a
> *savings* of 86 bytes in this one case. Note we're saving mainly code
> (.text) size here.
If s/error[123]/error/ in your testcase above, -O2 -n IA-32, I get
108 bytes without -DOPT in .text+.rodata.str1.1 sections, while
133 bytes with -DOPT.
The problem is especially when the same error message is used in multiple .o
files with differing __FILE__ (and __LINE__). Within one file, maybe
with -funit-at-a-time, the compiler can see how many such printf's are there
and either optimize or not optimize this depending on what saves more.
But with SHF_MERGE, two strings from completely different files can
be merged together (but cannot if -DOPT).
What could be done is to do the above transformation only in the likely
blocks and avoid them in unlikely ones.
Jakub