Bug 15559 - [3.3/3.4/4.0 Regression] misses opportunity for hoisting an expression that would simplify control flow
Summary: [3.3/3.4/4.0 Regression] misses opportunity for hoisting an expression that w...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.0.0
: P3 minor
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization, TREE
Depends on:
Blocks: 16996 5738 23286
  Show dependency treegraph
 
Reported: 2004-05-21 04:30 UTC by Andrew Pinski
Modified: 2023-12-28 07:18 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 2.95.3
Known to fail: 4.0.0 3.0.4 3.2.2
Last reconfirmed: 2004-12-05 04:12:47


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2004-05-21 04:30:36 UTC
int f(int i, int b, int *c)
{
  int ii;
  if (b)
   ii = i +1;
  else
   {
     *c = ii = i+1;
   }
  return ii;
}

Note I added compile time hog and memory hog as this causes too many bb to be there 
and more RTL than needed.
Comment 1 Giovanni Bajo 2004-05-21 12:35:33 UTC
Confirmed, but I don't see it happening at the RTL level either in 3.5.0, so 
I'll remove the TREE keyword.

The optimization did happen with 2.95.3 though. I'll mark it as a regression, 
even if I expect only a tree-level solution to happen (maybe already with 
GCSE), so it won't probably be fixed for the 3.3 branch or 3.4 branch.
Comment 2 Giovanni Bajo 2004-05-21 12:36:37 UTC
(In reply to comment #1)

> (maybe already with GCSE)
                      ^^^^ I meant GVN-PRE

Comment 3 Andrew Pinski 2004-05-21 12:59:50 UTC
I had forgot to say it works on powerpc-apple-darwin with all compilers so that is why I had TREE there.
Comment 4 Andrew Pinski 2004-05-21 13:07:58 UTC
I should note that it does happen at -Os on x86-pc-linux-gnu.
Comment 5 Gabriel Dos Reis 2004-05-21 14:47:10 UTC
Subject: Re:  [3.3/3.4/3.5 Regression] SSAPRE misses obivous redudent expression

"giovannibajo at libero dot it" <gcc-bugzilla@gcc.gnu.org> writes:

| even if I expect only a tree-level solution to happen (maybe already with 
| GCSE), so it won't probably be fixed for the 3.3 branch or 3.4 branch.

yes, you're right about 3.3.x.

-- Gaby
Comment 6 Daniel Berlin 2004-05-22 00:08:45 UTC
This should be fixed in GVNPRE.
Comment 7 Daniel Berlin 2004-06-10 16:05:27 UTC
Actually, i'm not sure what you expect to happen here.
We won't hoist this because there is no point in hoisting this, it doesn't reduce the total number of 
computations along any path, but does increase the lifetime.
There is nothing redundant along any single path in the program.
Comment 8 Giovanni Bajo 2004-06-10 16:12:40 UTC
yes, but if GVNPRE hoists the operation, we end up with:

int f(int i, int b, int *c)
{
  int ii;
  ii = i+1;
  if (b)
    ;
  else
    *c = ii;
  return ii;
}

that can be later simplified to:

int f(int i, int b, int *c)
{
  int ii;
  ii = i+1;
  if (!b)
    *c = ii;
  return ii;
}
Comment 9 Daniel Berlin 2004-06-10 16:45:56 UTC
Theoretically yes, but no PRE algorithm will do what you suggest, you need a generic code hoisting 
algorithm.  The transformation you suggest violates the optimality conditions of PRE, even if it can later 
make better code, so it wouldn't be performed.
In short, PRE is for partial redundancies, not a cost based generic code hoister, so this is not a case of 
PRE missing obvious redundant expressions. There is no redundant expression (it occurs once along 
each path) here that it could eliminate, there is simply an expression that could be hoisted one block 
up.
Comment 10 Andrew Pinski 2004-11-15 02:17:28 UTC
An example of where not doing hurts:
  int ii;
int f(int i, int b, int *c)
{
  if (b)
   ii = i +1;
  else
   {
     *c = ii = i+1;
   }
  return ii;
}

As there is a store to ii and then a load from it.
Comment 11 Steven Bosscher 2004-11-15 07:53:44 UTC
Not a hog, just a missed optimization. 
 
Let's reserve the *hog keywords for *real* hogs... 
Comment 12 Daniel Berlin 2004-11-23 02:49:36 UTC
(In reply to comment #10)
> An example of where not doing hurts:
>   int ii;
> int f(int i, int b, int *c)
> {
>   if (b)
>    ii = i +1;
>   else
>    {
>      *c = ii = i+1;
>    }
>   return ii;
> }
> 
> As there is a store to ii and then a load from it.


I'm not sure what you are talking about.
At the tree level,  there is only a store.
Comment 13 Daniel Berlin 2004-11-23 02:53:08 UTC
(In reply to comment #8)
> yes, but if GVNPRE hoists the operation, we end up with:
> 
> int f(int i, int b, int *c)
> {
>   int ii;
>   ii = i+1;
>   if (b)
>     ;
>   else
>     *c = ii;
>   return ii;
> }
> 
> that can be later simplified to:
> 
> int f(int i, int b, int *c)
> {
>   int ii;
>   ii = i+1;
>   if (!b)
>     *c = ii;
>   return ii;
> }
> 

This is still not faster code, only smaller code.
And you'll note that with -Os, this is what we do.


In any case, i have no plan sto make GVN-PRE do this type of hoisting, as i'm
not so interested in code size.
Comment 14 Steven Bosscher 2004-12-12 00:06:05 UTC
Gosh, I don't even see how this is a regression.  Geez.  Come on guys.
Comment 15 Steven Bosscher 2005-01-21 13:46:11 UTC
Mark, can we move the milestone on this one please?  There is no way 
this will be fixed for GCC 4.0. 
 
Comment 16 Mark Mitchell 2005-01-21 17:12:15 UTC
I'm going to go a step further and mark this INVALID.

Since we already do the right thing at -Os, and there's no evidence that we're
actually generating slower code at -O2, I'm not worried about this issue.  If
there's evidence that the code we're generating is slower than with a previous
compiler, post assembly code and timing information that shows that.