This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Patch to add __builtin_printf("string\n") -> puts("string")


"Kaveh R. Ghazi" <ghazi@caip.rutgers.edu> writes:

|  > From: Raja R Harinath <harinath@cs.umn.edu>
|  > 
|  > Raja R Harinath <harinath@cs.umn.edu> writes:
|  > > "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu> writes:
|  > > > 	printf("string\n") -> puts("string")
|  > > 
|  > > Isn't this a size pessimization: you may need to store two copies of
|  > > the constant string -- one with the trailing '\n' and one without.
|  > > Especially in the case
|  > > 
|  > >    const char *p = "foo\n";
|  > >    void bar () { printf(p); }
| 
| In the given example, the printf call site sees a pointer variable,
| not a string constant, so the optimization isn't performed.  Its only
| performed for cases like printf("foo\n") where the string constant is
| explicit.

But, what if, in the not so distant future, the front-end has
tree-based optimization which replaces p with "foo\n" ?

It is my opinion code optimization should come after correct
semantics, not before.

-- Gaby
CodeSourcery, LLC                             http://www.codesourcery.com

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]