This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

[Bug tree-optimization/21982] GCC should combine adjacent stdio calls


------- Additional Comments From dnovillo at redhat dot com  2005-06-09 16:55 -------
Subject: Re:  GCC should combine adjacent stdio calls

On Thu, Jun 09, 2005 at 04:49:40PM -0000, ghazi at gcc dot gnu dot org wrote:
> 
> ------- Additional Comments From ghazi at gcc dot gnu dot org  2005-06-09 16:49 -------
> (In reply to comment #4)
> > (In reply to comment #1)
> > > 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++);
> > > 
> > There should be little danger of this.  Side-effects are explicitly exposed in
> > GIMPLE.  As long as the printf() calls are adjacent, we should be able to
> > combine them.
> > Diego.
> 
> I'm not sure.  In my specific example above, after the combination we don't 
> know which i++ gets executed first because the order is not guaranteed within 
> an argument list of a single function call (right?)  So if we want to include 
> combinations whose arguments have side-effects, we have to prove they don't 
> interact with any other arguments.
> 
But remember that we are not optimizing C, we are optimizing
GIMPLE.  And in GIMPLE we don't have those problems.  Here's what
the tree optimizers see:

i_3 = i_1 + 1;
printf (&"%d"[0], i_1);
printf (&"%d"[0], i_3);


Those two calls to printf can be merged.  The order of evaluation
has been decided by the gimplifier.  Whether that's right or
wrong for C, I couldn't say, all I know is that for the
optimizers, those two printf calls look mergeable.


Diego.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21982


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