------- Additional Comments From dnovillo at redhat dot com 2005-06-09 19:03 ------- Subject: Re: GCC should combine adjacent stdio calls
On Thu, Jun 09, 2005 at 05:02:28PM -0000, ghazi at gcc dot gnu dot org wrote: > int i=0, j=2; > printf("%d", i); > j++; > printf("%d", j); > > Pushing the first printf further down, this could be reordered as: > int i=0, j=2; > j++; > printf("%d", i); > printf("%d", j); > > which would expose another combination possibility. > > Paul seemed to think this wasn't hard with the existing infrastructure, and > that was two years ago. > Oh, absolutely. The algorithm I'm using will naturally do this. This is a purely local transformation, we obviously cannot merge builtins in different control flow paths, so the transformation goes like this: when we get to a builtin, we try to merge it with a previously found builtin. The only time we reset the concept of "previously found builtin" is when we find a CALL_EXPR or an ASM_EXPR which are the only ones that may have side-effects affecting the output of the program. If the program manipulates the same FILE * that is being used by the stdio calls, then we'd lose. But I think that's fair game, right? Diego. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21982