This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] moving phi nodes?
- From: Richard Henderson <rth at redhat dot com>
- To: gcc at gcc dot gnu dot org
- Date: Sat, 15 Nov 2003 22:25:17 -0800
- Subject: [tree-ssa] moving phi nodes?
One jump threading case that we're currently missing, sorely,
is of the form:
int foo(int p, int q)
{
int i = 0;
if (p)
i = q;
if (i != 0)
bar ();
return i;
}
>From the t28.dce2 dump:
# BLOCK 0
# PRED: ENTRY (fallthru,exec)
if (p_3 != 0) goto <Uc910>; else goto <Uc984>;
# SUCC: 2 (false,exec) 1 (true,exec)
# BLOCK 1
# PRED: 0 (true,exec)
<Uc910>:;
# SUCC: 2 (fallthru,exec)
# BLOCK 2
# PRED: 0 (false,exec) 1 (fallthru,exec)
# i_1 = PHI <0(0), q_4(1)>;
<Uc984>:;
if (i_1 != 0) goto <Uc9f8>; else goto <Uca6c>;
# SUCC: 4 (false,exec) 3 (true,exec)
# BLOCK 3
# PRED: 2 (true,exec)
<Uc9f8>:;
bar ();
# SUCC: 4 (fallthru,exec)
# BLOCK 4
# PRED: 2 (false,exec) 3 (fallthru,exec)
<Uca6c>:;
return i_1;
# SUCC: EXIT
We really should be threading the edge BB0->BB4, since it is known
that I == 0 when incoming to block 2. Except if we do this, we need
to move the PHI node for I:
# BLOCK 0
# PRED: ENTRY (fallthru,exec)
if (p_3 != 0) goto <Uc910>; else goto <Uca6c>;
# SUCC: 4 (false,exec) 1 (true,exec)
# BLOCK 1
# PRED: 0 (true,exec)
<Uc910>:;
# SUCC: 2 (fallthru,exec)
# BLOCK 2
# PRED: 1 (fallthru,exec)
<Uc984>:;
if (q_4 != 0) goto <Uc9f8>; else goto <Uca6c>;
# SUCC: 4 (false,exec) 3 (true,exec)
# BLOCK 3
# PRED: 2 (true,exec)
<Uc9f8>:;
bar ();
# SUCC: 4 (fallthru,exec)
# BLOCK 4
# PRED: 0 (false,exec) 2 (false,exec) 3 (fallthru,exec)
# i_1 = PHI <0(0), 0(2), q_4(3)>;
<Uca6c>:;
return i_1;
# SUCC: EXIT
Moving the PHI node is non-trivial. Anyone know of a way to do it that
doesn't require just dropping all the SSA names and starting over? Do
we have any other gimple pass planned or desired that would take care
of this as a side effect?
Incidentally, this optimization is performed by the rtl .14.bypass
gcse pass.
r~