public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/37997]  New: PHI translation does not simplify to non-constants
@ 2008-11-02 15:32 rguenth at gcc dot gnu dot org
  0 siblings, 0 replies; only message in thread
From: rguenth at gcc dot gnu dot org @ 2008-11-02 15:32 UTC (permalink / raw)
  To: gcc-bugs

Split from PR37542.

int foo (int i, int b)
{
  int mask;
  int result;
  if (b)
    mask = -1;
  else
    mask = 0;
  result = result & mask;
  return result;
}

should be optimized to

int foo (int i, int b)
{
  int mask;
  int result;
  if (b)
    result = result;
  else
    result = 0;
  return result;
}

But we need to be careful with simplifying to SSA_NAMEs as the following
example
shows:

int foo (int i, int b)
{
  int mask;
  int result;
  if (b)
    mask = -1;
  else
    mask = 0;
  result = i + 1;
  result = result & mask;
  return result;
}

we have a phi-translation for result & mask that is 0 or result dependent
on the path through the CFG.  But we cannot insert this as a PHI as one
argument (result with value i + 1) is not available there.

The PRE of 4.3 inserts i + 1, re-generating the expression recursively and
exposing a code hoisting opportunity:

<bb 2>:
  if (b_2(D) != 0)
    goto <bb 5>;
  else
    goto <bb 3>;

<bb 5>:
  pretmp.6_10 = i_5(D) + 1;
  pretmp.6_11 = pretmp.6_10;
  goto <bb 4>;

<bb 3>:
  pretmp.6_13 = i_5(D) + 1;

<bb 4>:
  # prephitmp.7_14 = PHI <pretmp.6_10(5), pretmp.6_13(3)>
  # prephitmp.7_12 = PHI <pretmp.6_11(5), 0(3)>
  # mask_1 = PHI <-1(5), 0(3)>
  result_6 = prephitmp.7_14;
  result_7 = prephitmp.7_12;
  return result_7;

I don't think we want to do this now (without code hoisting implemented), but
for cases where result_6 is available we surely want it.

I'm trying to find a way to detect whether it is safe to phi-translate to
result_6.


-- 
           Summary: PHI translation does not simplify to non-constants
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rguenth at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-11-02 15:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-02 15:32 [Bug tree-optimization/37997] New: PHI translation does not simplify to non-constants rguenth 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).