> I suppose the CFG verifier should also catch this. I wonder how this can
> lead to wrong code as opossed to infinite loop?
> I can imagine DCE being confused about non-control-flow stmt and conclude
> the abnormal path as the path leaving the loop. I will look into the
> testcase more.
<bb 4063>:
# DEBUG id => e_186
_11422 = atree__unchecked_access__node4.localalias.3007 (e_186);
<bb 4064>:
# DEBUG id => NULL
# DEBUG n => _11422
# DEBUG n => NULL
if (_11422 == 0)
goto <bb 4097> (<L255>);
else
goto <bb 4065>;
The next block is:
<bb 4065>:
# DEBUG id => e_186
goto <bb 4046>;
and has the stalled ABNORMAL flag. This causes the latch edge to be split.
When the PHI node consuming _11422 is processed:
processing: e_186 = PHI <e_7741(4046), _11422(4164)>
the following code is invoked:
if (aggressive && !degenerate_phi_p (stmt))
{
for (k = 0; k < gimple_phi_num_args (stmt); k++)
{
basic_block arg_bb = gimple_phi_arg_edge (phi, k)->src;
if (gimple_bb (stmt)
!= get_immediate_dominator (CDI_POST_DOMINATORS, arg_bb))
{
if (!bitmap_bit_p (last_stmt_necessary, arg_bb->index))
mark_last_stmt_necessary (arg_bb);
}
else if (arg_bb != ENTRY_BLOCK_PTR_FOR_FN (cfun)
&& !bitmap_bit_p (visited_control_parents,
arg_bb->index))
mark_control_dependent_edges_necessary (arg_bb, true);
}
}
arg_bb is the immediate postdominator of gimple_bb (stmt) so the first
condition is false. And the second condition is also false because arg_bb was
already marked in visited_control_parents from:
FOR_EACH_LOOP (loop, 0)
if (!finite_loop_p (loop))
{
if (dump_file)
fprintf (dump_file, "can not prove finiteness of loop %i\n",
loop->num);
mark_control_dependent_edges_necessary (loop->latch, false);
}
I'm not quite sure where the logic goes wrong, but the comment just above the
first quoted block of code makes one think it is a bit fragile.
In any case, the fixlet I posted was slightly off, so here is the patch I have
installed as obvious after testing on x86-64/Linux.
PR tree-optimization/65337
* tree-ssa-pre.c (eliminate): Also clean up abnormal edges if need be.
--
Eric Botcazou
Index: tree-ssa-pre.c
===================================================================
--- tree-ssa-pre.c (revision 231856)
+++ tree-ssa-pre.c (working copy)
@@ -4499,6 +4499,8 @@ eliminate (bool do_pre)
unlink_stmt_vdef (stmt);
if (gsi_remove (&gsi, true))
bitmap_set_bit (need_eh_cleanup, bb->index);
+ if (is_gimple_call (stmt) && stmt_can_make_abnormal_goto (stmt))
+ bitmap_set_bit (need_ab_cleanup, bb->index);
release_defs (stmt);
}