public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58005] New: missed optimization printf constant string
@ 2013-07-27 19:44 dushistov at mail dot ru
2013-07-27 19:55 ` [Bug tree-optimization/58005] " paolo.carlini at oracle dot com
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: dushistov at mail dot ru @ 2013-07-27 19:44 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58005
Bug ID: 58005
Summary: missed optimization printf constant string
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dushistov at mail dot ru
Simple code:
#include <cstdio>
int main()
{
printf("%s: test1\n", __PRETTY_FUNCTION__);//1
printf("test2\n");//2
return 0;
}
compiled to:
callq 4005a0 <__printf_chk@plt> (1)
and to
callq 400590 <puts@plt> for (2)
I think that, because of __PRETTY_FUNCTION__ is known during compile time, it
is also possible converting (1) to "puts" call.
This optimization can help speedup loging functionality.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/58005] missed optimization printf constant string
2013-07-27 19:44 [Bug c++/58005] New: missed optimization printf constant string dushistov at mail dot ru
@ 2013-07-27 19:55 ` paolo.carlini at oracle dot com
2013-07-27 20:04 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-07-27 19:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58005
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
Component|c++ |tree-optimization
--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Something for Jakub, I think.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/58005] missed optimization printf constant string
2013-07-27 19:44 [Bug c++/58005] New: missed optimization printf constant string dushistov at mail dot ru
2013-07-27 19:55 ` [Bug tree-optimization/58005] " paolo.carlini at oracle dot com
@ 2013-07-27 20:04 ` pinskia at gcc dot gnu.org
2013-07-27 20:14 ` joseph at codesourcery dot com
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-07-27 20:04 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58005
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-07-27
Ever confirmed|0 |1
Severity|normal |enhancement
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed also happens in C (s/cstdio/stdio.h/).
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/58005] missed optimization printf constant string
2013-07-27 19:44 [Bug c++/58005] New: missed optimization printf constant string dushistov at mail dot ru
2013-07-27 19:55 ` [Bug tree-optimization/58005] " paolo.carlini at oracle dot com
2013-07-27 20:04 ` pinskia at gcc dot gnu.org
@ 2013-07-27 20:14 ` joseph at codesourcery dot com
2013-07-27 21:02 ` dushistov at mail dot ru
2013-09-23 19:45 ` daniel.santos at pobox dot com
4 siblings, 0 replies; 6+ messages in thread
From: joseph at codesourcery dot com @ 2013-07-27 20:14 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58005
--- Comment #3 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
Such an optimization can increase code size (well, the total size of
string constants in the program) if the same format string is used with
many different arguments, so it may not always be a good idea (at least
with -Os).
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/58005] missed optimization printf constant string
2013-07-27 19:44 [Bug c++/58005] New: missed optimization printf constant string dushistov at mail dot ru
` (2 preceding siblings ...)
2013-07-27 20:14 ` joseph at codesourcery dot com
@ 2013-07-27 21:02 ` dushistov at mail dot ru
2013-09-23 19:45 ` daniel.santos at pobox dot com
4 siblings, 0 replies; 6+ messages in thread
From: dushistov at mail dot ru @ 2013-07-27 21:02 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58005
--- Comment #4 from Evgeniy Dushistov <dushistov at mail dot ru> ---
>Such an optimization can increase code size
>if the same format string is used with
>many different arguments,
may be then two fputs calls?
fputs(__PRETTY_FUNCTION__, stdout);
fputs("%s: test1\n" + 2/*skip format*/, stdout);
yeah, still we have two calls vs one(bad for -Os),
but we not introduce new string constants,
so it is suitable optimization for -Ofast.
In such test:
for (int i = 0; i < 100000; ++i) {
#ifdef OPTIMIZATION
fputs(__PRETTY_FUNCTION__, stdout);
fputs("%s: test1\n" + 2, stdout);
#else
printf("%s: test1\n", __PRETTY_FUNCTION__);
#endif
}
fputs win with
real 0m0.005s
user 0m0.000s
sys 0m0.000s
vs printf
real 0m0.011s
user 0m0.010s
sys 0m0.000s
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/58005] missed optimization printf constant string
2013-07-27 19:44 [Bug c++/58005] New: missed optimization printf constant string dushistov at mail dot ru
` (3 preceding siblings ...)
2013-07-27 21:02 ` dushistov at mail dot ru
@ 2013-09-23 19:45 ` daniel.santos at pobox dot com
4 siblings, 0 replies; 6+ messages in thread
From: daniel.santos at pobox dot com @ 2013-09-23 19:45 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58005
Daniel Santos <daniel.santos at pobox dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |daniel.santos at pobox dot com
--- Comment #5 from Daniel Santos <daniel.santos at pobox dot com> ---
(In reply to joseph@codesourcery.com from comment #3)
> Such an optimization can increase code size (well, the total size of
> string constants in the program) if the same format string is used with
> many different arguments, so it may not always be a good idea (at least
> with -Os).
Yeah, I agree. Such a subtle optimization would be bad for many people who
intentionally reuse a format string to reduce the data size and then only to
have that thwarted by the compiler. Typically, printfs don't reside in
performance sensitive sections of code.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-09-23 19:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-27 19:44 [Bug c++/58005] New: missed optimization printf constant string dushistov at mail dot ru
2013-07-27 19:55 ` [Bug tree-optimization/58005] " paolo.carlini at oracle dot com
2013-07-27 20:04 ` pinskia at gcc dot gnu.org
2013-07-27 20:14 ` joseph at codesourcery dot com
2013-07-27 21:02 ` dushistov at mail dot ru
2013-09-23 19:45 ` daniel.santos at pobox dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).