On Thu, 17 Feb 2022, Richard Biener wrote:
> On Tue, 15 Feb 2022, Jan Hubicka wrote:
>
> > > @@ -1272,7 +1275,7 @@ maybe_optimize_arith_overflow (gimple_stmt_iterator
> > > *gsi,
> > > contributes nothing to the program, and can be deleted. */
> > >
> > > static bool
> > > -eliminate_unnecessary_stmts (void)
> > > +eliminate_unnecessary_stmts (bool aggressive)
> > > {
> > > bool something_changed = false;
> > > basic_block bb;
> > > @@ -1366,7 +1369,9 @@ eliminate_unnecessary_stmts (void)
> > > break;
> > > }
> > > }
> > > - if (!dead)
> > > + if (!dead
> > > + && (!aggressive
> > > + || bitmap_bit_p (visited_control_parents, bb->index)))
> >
> > It seems to me that it may be worth to consider case where
> > visited_control_parents is 0 while all basic blocks in the CD relation
> > are live for different reasons. I suppose this can happen in more
> > complex CFGs when the other arms of conditionals are live...
>
> It's a bit difficult to do in this place though since we might already
> have altered those blocks (and we need to check not for the block being
> live but for its control stmt). I suppose we could use the
> last_stmt_necessary bitmap. I'll do some statistics to see whether
> this helps.
So it does help. The visited_control_parents catches
44010 from 44033 candidates and the remaining 23 are catched by doing
EXECUTE_IF_SET_IN_BITMAP (cd->get_edges_dependent_on
(bb->index),
0, edge_number, bi)
{
basic_block cd_bb = cd->get_edge_src
(edge_number);
if (cd_bb != bb
&& !bitmap_bit_p (last_stmt_necessary,
cd_bb->index))
{
dead = true;
break;
}
}
in addition to that simple check. That means for all files in gcc/
the patch would be a no-op but it still fixes the problematical case.
I'll put an adjusted patch to testing.
Richard.