[Bug ipa/100034] missed optimization for dead code elimination at -O3 (vs. -O1, -Os, -O2)
luoxhu at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jun 9 03:04:05 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100034
--- Comment #2 from luoxhu at gcc dot gnu.org ---
(In reply to Richard Biener from comment #1)
> Looks related to PR99991 - we do an IPA SRA clone but fail to inline it and
> thus we end up with
>
> void d.isra ()
> {
> int D.1980;
> int g.2_1;
>
> <bb 2> [local count: 10631108]:
>
> <bb 3> [local count: 96646437]:
> g.2_1 = 0;
> if (g.2_1 != 0)
> goto <bb 3>; [89.00%]
> else
> goto <bb 4>; [11.00%]
>
> <bb 4> [local count: 1073741824]:
> foo ();
> goto <bb 4>; [100.00%]
>
> }
>
> int main ()
> {
> int a.0_2;
> int b.1_3;
>
> <bb 2> [local count: 59461674]:
> goto <bb 6>; [100.00%]
>
> <bb 3> [local count: 1014686025]:
> a.0_2 = a;
> if (a.0_2 == 0)
> goto <bb 4>; [99.96%]
> else
> goto <bb 5>; [0.04%]
>
> <bb 4> [local count: 1014280151]:
> // predicted unlikely by continue predictor.
> goto <bb 6>; [100.00%]
>
> <bb 5> [local count: 405874]:
> d.isra ();
>
> <bb 6> [local count: 1073741824]:
> b.1_3 = b;
> if (b.1_3 != 0)
> goto <bb 3>; [94.50%]
> else
> goto <bb 7>; [5.50%]
>
> <bb 7> [local count: 59055800]:
> return 0;
>
> }
>
> where we optimize main to 'return 0' but fail to elide the unused d.isra.
>
> So also a dup of the cases where a late IPA function reclaim is missing.
early_inliner inlines e to main in -O3 due to param_early_inlining_insns is 14
for O3, but it is 6 for -O2, so want_early_inline_function_p returns different.
Then ipa-inline fails to inline d.isra by inline_functions_called_once as it is
called by two callees e->d.isra and main->d.isra.
But The two d.isra calls are removed by gimple 102t.ccp2 pass after all ipa
passes:
pr100034.O3.c.103t.objsz1:
;; Function d.isra (d.isra.0, funcdef_no=4, decl_uid=2014, cgraph_uid=7,
symbol_order=10) (executed once)
void d.isra ()
{
int D.2016;
<bb 2> [local count: 10631108]:
<bb 3> [local count: 1073741824]:
foo ();
goto <bb 3>; [100.00%]
}
;; Function e (e, funcdef_no=2, decl_uid=1994, cgraph_uid=3, symbol_order=6)
void e ()
{
<bb 2> [local count: 59461674]:
return;
}
;; Function main (main, funcdef_no=3, decl_uid=1999, cgraph_uid=4,
symbol_order=7) (executed once)
int main ()
{
<bb 2> [local count: 59461674]:
return 0;
}
Currently all IPA passes are run before gimple optimizations, is it possible to
run some passes like pass_rebuild_cgraph_edges and pass_ipa_remove_symbols
after some gimple optimisations expose new opertunities?
More information about the Gcc-bugs
mailing list