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 optimization/15349] New: [tree-ssa] Merge two phi nodes.


void bar (void);

int
foo (int a, int b)
{
  int t;

  if (b)
    {
      if (a)
	t = 3;
      else
	t = 5;

      if (t)
	a++;
    }
  else
    t = 7;

  return t - 1;
}

I get:

foo (a, b)
{
  int t;

<bb 0>:
  if (b_3 != 0) goto <L0>; else goto <L7>;

<L0>:;
  if (a_6 != 0) goto <L1>; else goto <L3>;

<L1>:;

  # t_1 = PHI <5(1), 3(2)>;
<L3>:;

  # t_2 = PHI <7(0), t_1(3)>;
<L7>:;
  return t_2 - 1;

}

Note that we can merge the first PHI into the second one like so:

  # t_2 = PHI <7(0), 5(1), 3(2)>;

by replacing goto <L1>; with goto <L7>;

Note that this optimization is pretty important because I see alias.c
containing the following:

<L191>:;

  # iftmp.1496_89 = PHI <0(139), 1(138)>;
<L192>:;
  iftmp.1493_304 = iftmp.1496_89 != 0;

  # iftmp.1493_88 = PHI <iftmp.1493_304(140), iftmp.1493_316(136)>;
<L193>:;
  if (iftmp.1493_88) goto <L194>; else goto <L202>;

Once PR 14797 is solved, the above code should become something like

<L191>:;

  # iftmp.1493_304 = PHI <0(139), 1(138)>;
<L192>:;

  # iftmp.1493_88 = PHI <iftmp.1493_304(140), iftmp.1493_316(136)>;
<L193>:;
  if (iftmp.1493_88) goto <L194>; else goto <L202>;

Once this PR is solved, we would have

<L192>:;

  # iftmp.1493_88 = PHI <0(139), 1(138), iftmp.1493_316(136)>;
<L193>:;
  if (iftmp.1493_88) goto <L194>; else goto <L202>;

Now it's trivial to redirect jumps from bb 139 and bb 138
to <L202> and <L194>, respectively, provided that nobody else
uses iftmp.1493_88.

-- 
           Summary: [tree-ssa] Merge two phi nodes.
           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=15349


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