public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ipa/100034] New: missed optimization for dead code elimination at -O3 (vs. -O1, -Os, -O2)
@ 2021-04-11 14:44 zhendong.su at inf dot ethz.ch
2021-04-12 8:53 ` [Bug ipa/100034] " rguenth at gcc dot gnu.org
2022-06-09 3:04 ` luoxhu at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2021-04-11 14:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100034
Bug ID: 100034
Summary: missed optimization for dead code elimination at -O3
(vs. -O1, -Os, -O2)
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: zhendong.su at inf dot ethz.ch
CC: marxin at gcc dot gnu.org
Target Milestone: ---
[641] % gcctk -v
Using built-in specs.
COLLECT_GCC=gcctk
COLLECT_LTO_WRAPPER=/local/suz-local/software/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/11.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk/configure --disable-bootstrap
--prefix=/local/suz-local/software/local/gcc-trunk --enable-languages=c,c++
--disable-werror --enable-multilib --with-system-zlib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.1 20210411 (experimental) [master revision
1d54b138417:e83b9cf4549:936d500dfc17f58f2507ecd0f7f26e4f197052ee] (GCC)
[642] %
[642] % gcctk -O1 -S -o O1.s small.c
[643] % gcctk -O3 -S -o O3.s small.c
[644] %
[644] % wc O1.s O3.s
23 45 420 O1.s
41 78 697 O3.s
64 123 1117 total
[645] %
[645] % grep foo O1.s
[646] % grep foo O3.s
call foo
[647] %
[647] % cat small.c
extern void foo(void);
static int a, b, f, g;
static int d() {
while (g)
f = 0;
while (1)
foo();
}
static void c() { d (); }
void e() {
while (b) {
if (!a)
continue;
c();
}
}
int main() {
e();
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug ipa/100034] missed optimization for dead code elimination at -O3 (vs. -O1, -Os, -O2)
2021-04-11 14:44 [Bug ipa/100034] New: missed optimization for dead code elimination at -O3 (vs. -O1, -Os, -O2) zhendong.su at inf dot ethz.ch
@ 2021-04-12 8:53 ` rguenth at gcc dot gnu.org
2022-06-09 3:04 ` luoxhu at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-04-12 8:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100034
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Version|unknown |11.0
Keywords| |missed-optimization
CC| |hubicka at gcc dot gnu.org
Last reconfirmed| |2021-04-12
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug ipa/100034] missed optimization for dead code elimination at -O3 (vs. -O1, -Os, -O2)
2021-04-11 14:44 [Bug ipa/100034] New: missed optimization for dead code elimination at -O3 (vs. -O1, -Os, -O2) zhendong.su at inf dot ethz.ch
2021-04-12 8:53 ` [Bug ipa/100034] " rguenth at gcc dot gnu.org
@ 2022-06-09 3:04 ` luoxhu at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: luoxhu at gcc dot gnu.org @ 2022-06-09 3:04 UTC (permalink / raw)
To: gcc-bugs
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?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-09 3:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-11 14:44 [Bug ipa/100034] New: missed optimization for dead code elimination at -O3 (vs. -O1, -Os, -O2) zhendong.su at inf dot ethz.ch
2021-04-12 8:53 ` [Bug ipa/100034] " rguenth at gcc dot gnu.org
2022-06-09 3:04 ` luoxhu at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).