public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/38204]  New: PRE for post dominating expressions
@ 2008-11-20 17:00 dann at godzilla dot ics dot uci dot edu
  2008-11-21  6:43 ` [Bug middle-end/38204] " steven at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: dann at godzilla dot ics dot uci dot edu @ 2008-11-20 17:00 UTC (permalink / raw)
  To: gcc-bugs

For this function:
int test (int a, int b, int c, int g)
{
  int d, e;
  if (a)
    d = b * c;
  else
    d = b - c;
  e = b * c + g;
  return d + e;
}

the multiply expression is moved to both branches of the "if", it would be
better to move it before the "if".  Intel's compiler does that.


-- 
           Summary: PRE for post dominating expressions
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dann at godzilla dot ics dot uci dot edu
  GCC host triplet: i386-pc-linux


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug middle-end/38204] PRE for post dominating expressions
  2008-11-20 17:00 [Bug middle-end/38204] New: PRE for post dominating expressions dann at godzilla dot ics dot uci dot edu
@ 2008-11-21  6:43 ` steven at gcc dot gnu dot org
  2008-11-21 16:57 ` dberlin at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: steven at gcc dot gnu dot org @ 2008-11-21  6:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from steven at gcc dot gnu dot org  2008-11-21 06:41 -------


*** This bug has been marked as a duplicate of 23286 ***


-- 

steven at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug middle-end/38204] PRE for post dominating expressions
  2008-11-20 17:00 [Bug middle-end/38204] New: PRE for post dominating expressions dann at godzilla dot ics dot uci dot edu
  2008-11-21  6:43 ` [Bug middle-end/38204] " steven at gcc dot gnu dot org
@ 2008-11-21 16:57 ` dberlin at gcc dot gnu dot org
  2008-11-22  0:36 ` davidxl at gcc dot gnu dot org
  2008-12-01 22:14 ` steven at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: dberlin at gcc dot gnu dot org @ 2008-11-21 16:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from dberlin at gcc dot gnu dot org  2008-11-21 16:55 -------
(In reply to comment #0)
> For this function:
> int test (int a, int b, int c, int g)
> {
>   int d, e;
>   if (a)
>     d = b * c;
>   else
>     d = b - c;
>   e = b * c + g;
>   return d + e;
> }
> 
> the multiply expression is moved to both branches of the "if", it would be
> better to move it before the "if".  Intel's compiler does that.
> 

Moving it before the if is a code size optimization that also happens to extend
the lifetime of the multiply.
So "better" is a relative term.


-- 


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug middle-end/38204] PRE for post dominating expressions
  2008-11-20 17:00 [Bug middle-end/38204] New: PRE for post dominating expressions dann at godzilla dot ics dot uci dot edu
  2008-11-21  6:43 ` [Bug middle-end/38204] " steven at gcc dot gnu dot org
  2008-11-21 16:57 ` dberlin at gcc dot gnu dot org
@ 2008-11-22  0:36 ` davidxl at gcc dot gnu dot org
  2008-12-01 22:14 ` steven at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: davidxl at gcc dot gnu dot org @ 2008-11-22  0:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from davidxl at gcc dot gnu dot org  2008-11-22 00:35 -------
(In reply to comment #2)
> (In reply to comment #0)
> > For this function:
> > int test (int a, int b, int c, int g)
> > {
> >   int d, e;
> >   if (a)
> >     d = b * c;
> >   else
> >     d = b - c;
> >   e = b * c + g;
> >   return d + e;
> > }
> > 
> > the multiply expression is moved to both branches of the "if", it would be
> > better to move it before the "if".  Intel's compiler does that.
> > 
> 
> Moving it before the if is a code size optimization that also happens to extend
> the lifetime of the multiply.
> So "better" is a relative term.
> 

As a side note: 

PRE is made aware of the impact of code size bloat and is -Os friendly.  for
instance, if multiple insertions are needed, the PRE won't happen with -Os.

if (..)
   expr
else if (..)
   ...
else if (..)
   ...
else
   ...

expr

While this is good, if hoisting opportunities exposed by PRE is materialized,
this PRE should still be allowed under -Os.

(-Os in gcc is not well tuned -- many optimizations are simply turned off in
fear of code bloat without analysis -- the end result is often lost
opportunities for code clean up --> end up with a slower and BIGGer binary).

The hoisting increase tmp life time slightly, but it also adds more scheduling
freedom as a good effect.

David 


-- 


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug middle-end/38204] PRE for post dominating expressions
  2008-11-20 17:00 [Bug middle-end/38204] New: PRE for post dominating expressions dann at godzilla dot ics dot uci dot edu
                   ` (2 preceding siblings ...)
  2008-11-22  0:36 ` davidxl at gcc dot gnu dot org
@ 2008-12-01 22:14 ` steven at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: steven at gcc dot gnu dot org @ 2008-12-01 22:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from steven at gcc dot gnu dot org  2008-12-01 22:12 -------
davidxl, my latest patch to bug 23286 (tree-hoist_v3.diff) makes PRE in
tree-ssa-pre.c code-size aware.  I have tested this with CSiBE on
mips-unknown-elf.

Without the patch, code size at -Os with PRE enabled is ~17% larger than -Os
without PRE.

With the patch, the code size increase with -Os and PRE enabled is 0.2%.  

With the patch and with tree hoisting enabled at -Os, code size is reduced by
just a little less than 1%.

With the patch and with tree hoisting enabled at -Os but RTL code hoisting
disabled (i.e. the pass in gcse.c), code size is reduced by just a little less
than 0.6%.  (The RTL pass will be necessary mostly to hoist copies from
out-of-ssa, and frame/stack pointer adjustments.)

davidxl, if you have some time or someone else with time to play with this
further, that'd be much appreciated.  I've done my part, but having done the
trick, the fun is gone and I have no intention to persue code-size aware PRE
further ;-)


-- 


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-12-01 22:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-20 17:00 [Bug middle-end/38204] New: PRE for post dominating expressions dann at godzilla dot ics dot uci dot edu
2008-11-21  6:43 ` [Bug middle-end/38204] " steven at gcc dot gnu dot org
2008-11-21 16:57 ` dberlin at gcc dot gnu dot org
2008-11-22  0:36 ` davidxl at gcc dot gnu dot org
2008-12-01 22:14 ` steven at gcc dot gnu dot org

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).