public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/14797] New: [tree-ssa] propagate constants back to PHI
@ 2004-03-31 10:46 kazu at cs dot umass dot edu
  2004-03-31 12:44 ` [Bug optimization/14797] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-03-31 10:46 UTC (permalink / raw)
  To: gcc-bugs

Consider:

int
foo (int a)
{
  int b;

  if (a == 0)
    b = 0;
  else
    b = 1;

  return b + 1;
}

I get:

foo (a)
{
  int b;

<bb 0>:
  if (a_2 == 0) goto <L0>; else goto <L2>;

<L0>:;

  # b_1 = PHI <1(0), 0(1)>;
<L2>:;
  return b_1 + 1;

}

Note that PHI could absorb b_1 + 1.  That is, we could do something like:

foo (a)
{
  int b;

<bb 0>:
  if (a_2 == 0) goto <L0>; else goto <L2>;

<L0>:;

  # b_1 = PHI <2(0), 1(1)>;
<L2>:;
  return b_1;

}

-- 
           Summary: [tree-ssa] propagate constants back to PHI
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Keywords: pessimizes-code
          Severity: enhancement
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kazu at cs dot umass dot edu
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug optimization/14797] [tree-ssa] propagate constants back to PHI
  2004-03-31 10:46 [Bug optimization/14797] New: [tree-ssa] propagate constants back to PHI kazu at cs dot umass dot edu
@ 2004-03-31 12:44 ` pinskia at gcc dot gnu dot org
  2004-03-31 15:32 ` kazu at cs dot umass dot edu
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-31 12:44 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-03-31 12:44 -------
Really this should not propagate constants back to the PHI but change this code to, as this removes BB's 
and such, I know this example was to show what to do with PHI's but we can do better with this one 
(this part is a dup of a bug which I filed, bug 14466):
int
foo (int a)
{
  int b;
  b = a != 0;
  return b + 1;
}


Anyways here is a better example as there is no way to convert the comparsion into the PHI:
int
foo (int a)
{
  int b;

  if (a == 0)
    b = 700;
  else
    b = 200;

  return b + 1;
}
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-03-31 12:44:32
               date|                            |
   Target Milestone|---                         |tree-ssa


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


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

* [Bug optimization/14797] [tree-ssa] propagate constants back to PHI
  2004-03-31 10:46 [Bug optimization/14797] New: [tree-ssa] propagate constants back to PHI kazu at cs dot umass dot edu
  2004-03-31 12:44 ` [Bug optimization/14797] " pinskia at gcc dot gnu dot org
@ 2004-03-31 15:32 ` kazu at cs dot umass dot edu
  2004-03-31 16:14 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-03-31 15:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kazu at cs dot umass dot edu  2004-03-31 15:32 -------
I don't know where to draw a line.  Even for the last example, i386
port converts the code to

b = a != 0;
b--;
b &= 500;
b += 201;

but this would be a nightmare on ports without setcc (like h8).

Maybe we could keep anything more complex than "c = a COND b" in the
if-then-else form (assuming we don't want to introduce
machine-dependent if-conversion pass at tree level).  If we don't want
to rely on rtl optimizers to do if-conversion, we could put a flag to
"if" to indicate that that's an if-conversion candidate (just like
tail-call flag) and then do the if-conversion at the expand time.

-- 


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


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

* [Bug optimization/14797] [tree-ssa] propagate constants back to PHI
  2004-03-31 10:46 [Bug optimization/14797] New: [tree-ssa] propagate constants back to PHI kazu at cs dot umass dot edu
  2004-03-31 12:44 ` [Bug optimization/14797] " pinskia at gcc dot gnu dot org
  2004-03-31 15:32 ` kazu at cs dot umass dot edu
@ 2004-03-31 16:14 ` pinskia at gcc dot gnu dot org
  2004-05-24 19:23 ` [Bug tree-optimization/14797] " pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-31 16:14 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-03-31 16:14 -------
I also think we should keep anything more complex than c = a CMP b in the PHI form and that is what is 
done right now.

-- 


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


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

* [Bug tree-optimization/14797] [tree-ssa] propagate constants back to PHI
  2004-03-31 10:46 [Bug optimization/14797] New: [tree-ssa] propagate constants back to PHI kazu at cs dot umass dot edu
                   ` (2 preceding siblings ...)
  2004-03-31 16:14 ` pinskia at gcc dot gnu dot org
@ 2004-05-24 19:23 ` pinskia at gcc dot gnu dot org
  2005-01-31 14:46 ` kazu at cs dot umass dot edu
  2005-05-02  0:50 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-24 19:23 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|3.5.0                       |---


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


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

* [Bug tree-optimization/14797] [tree-ssa] propagate constants back to PHI
  2004-03-31 10:46 [Bug optimization/14797] New: [tree-ssa] propagate constants back to PHI kazu at cs dot umass dot edu
                   ` (3 preceding siblings ...)
  2004-05-24 19:23 ` [Bug tree-optimization/14797] " pinskia at gcc dot gnu dot org
@ 2005-01-31 14:46 ` kazu at cs dot umass dot edu
  2005-05-02  0:50 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: kazu at cs dot umass dot edu @ 2005-01-31 14:46 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kazu at cs dot umass dot edu  2005-01-31 14:46 -------
Seems like what I feared in comment #2 is going on.
Specifically, for the original test case, I get:

foo (a)
{
  _Bool D.1130;
  _Bool D.1129;
  int b;
  int D.1120;

<bb 0>:
  D.1129_5 = a_2 == 0;
  D.1130_6 = !D.1129_5;
  b_1 = (int) D.1130_6;
  D.1120_3 = b_1 + 1;
  return D.1120_3;

}

I don't know if it's correct to say PHI-OPT is run too early,
but at least it is blocking us to obtain:

# b_1 = PHI <2(0), 1(1)>;


-- 


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


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

* [Bug tree-optimization/14797] [tree-ssa] propagate constants back to PHI
  2004-03-31 10:46 [Bug optimization/14797] New: [tree-ssa] propagate constants back to PHI kazu at cs dot umass dot edu
                   ` (4 preceding siblings ...)
  2005-01-31 14:46 ` kazu at cs dot umass dot edu
@ 2005-05-02  0:50 ` pinskia at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-02  0:50 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-02 00:50 -------
Fixed via PRE for 4.0.0.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.0.0


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


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

end of thread, other threads:[~2005-05-02  0:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-31 10:46 [Bug optimization/14797] New: [tree-ssa] propagate constants back to PHI kazu at cs dot umass dot edu
2004-03-31 12:44 ` [Bug optimization/14797] " pinskia at gcc dot gnu dot org
2004-03-31 15:32 ` kazu at cs dot umass dot edu
2004-03-31 16:14 ` pinskia at gcc dot gnu dot org
2004-05-24 19:23 ` [Bug tree-optimization/14797] " pinskia at gcc dot gnu dot org
2005-01-31 14:46 ` kazu at cs dot umass dot edu
2005-05-02  0:50 ` pinskia 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).