------- Additional Comments From gcc-bugzilla at gcc dot gnu dot org 2005-06-09 16:11 ------- Subject: New: GCC should combine adjacent stdio calls
GCC should optimize adjacent stdio calls. For example: printf("foo %d %d\n", i, j); printf("bar %d %d\n", x, y); could instead be emitted as: printf("foo %d %d\nbar %d %d\n", i, j, x, y); More generally, you simply concatenate the format arguments and append all of the remaining first printf's arguments and then all of the second printf's arguments. You can also combine adjacent printf/puts and printf/putc: printf("format", args...); puts(s); -> printf("format%s\n", args..., s); printf("format", args...); putc(c); -> printf "format%c", args..., c); You can also combine adjacent f* variants of these stdio calls (fprintf, fputs, fputc) if the supplied streams are equivalent. One caveat, some format specifiers need special care. E.g. position speficiers must be adjusted. The %n specifier may preclude the optimization entirely. There might be other examples. -- Summary: GCC should combine adjacent stdio calls Product: gcc Version: 4.1.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P2 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ghazi at gcc dot gnu dot org CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21982 ------- Additional Comments From gcc-bugzilla at gcc dot gnu dot org 2005-06-09 16:11 ------- Subject: GCC should combine adjacent stdio calls ------- Additional Comments From ghazi at gcc dot gnu dot org 2005-06-09 13:01 ------- If side effects appear in the arguments, that also would be a problem, e.g.: printf("%d", i++); printf("%d", i++); should not be turned into: printf("%d%d", i++, i++); because we can't guarantee order of evaluation. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21982