public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/99835] New: missed optimization for dead code elimination at -O3 (vs. -O1)
@ 2021-03-30 17:27 zhendong.su at inf dot ethz.ch
  2021-03-31  8:08 ` [Bug ipa/99835] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2021-03-30 17:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99835

            Bug ID: 99835
           Summary: missed optimization for dead code elimination at -O3
                    (vs. -O1)
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhendong.su at inf dot ethz.ch
  Target Milestone: ---

[558] % 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 20210330 (experimental) [master revision
8aac913adfc:ff4ebc2f17c:65374af219f9c5c594951a07e766fe70c1136a1f] (GCC) 
[559] % 
[559] % gcctk -O1 -S -o O1.s small.c
[560] % gcctk -O3 -S -o O3.s small.c
[561] % 
[561] % wc O1.s O3.s
  23   45  420 O1.s
  35   66  615 O3.s
  58  111 1035 total
[562] % 
[562] % grep foo O1.s
[563] % grep foo O3.s
        jmp     foo
[564] % 
[564] % cat small.c
extern void foo(void);
static int a, d;
void b();
static int c() {
  foo();
  b();
}
void b() {
  while (d) {
    if (!a)
      break;
    c();
  }
}
int main() {
  b();
  return 0;
}

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug ipa/99835] missed optimization for dead code elimination at -O3 (vs. -O1)
  2021-03-30 17:27 [Bug tree-optimization/99835] New: missed optimization for dead code elimination at -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
@ 2021-03-31  8:08 ` rguenth at gcc dot gnu.org
  2021-03-31  8:14   ` Jan Hubicka
  2021-03-31  8:14 ` hubicka at ucw dot cz
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-03-31  8:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99835

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at gcc dot gnu.org,
                   |                            |marxin at gcc dot gnu.org
          Component|tree-optimization           |ipa
   Last reconfirmed|                            |2021-03-31
           Keywords|                            |missed-optimization
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
            Version|unknown                     |11.0

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
At -O3 the unused 'c' remains.  Likely different (recursive?) inlining makes us
process a cgraph cycle in different order and thus fail to elide the output
of 'c' (it's output first at -O3).

Fixing that would need processing cgraph SCCs with an extra IPA phase in main
optimization so we get a chance to do extra node removal (maybe order
the cycles so that functions we can elide - aka static ones - are processed
last).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Bug ipa/99835] missed optimization for dead code elimination at -O3 (vs. -O1)
  2021-03-31  8:08 ` [Bug ipa/99835] " rguenth at gcc dot gnu.org
@ 2021-03-31  8:14   ` Jan Hubicka
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Hubicka @ 2021-03-31  8:14 UTC (permalink / raw)
  To: rguenth at gcc dot gnu.org; +Cc: gcc-bugs

> At -O3 the unused 'c' remains.  Likely different (recursive?) inlining makes us
> process a cgraph cycle in different order and thus fail to elide the output
> of 'c' (it's output first at -O3).
> 
> Fixing that would need processing cgraph SCCs with an extra IPA phase in main
> optimization so we get a chance to do extra node removal (maybe order
> the cycles so that functions we can elide - aka static ones - are processed
> last).
That would tamper with optimizations that propagate from callee to
caller during late optimization, like IPA register allocation, stack
alignment propagation or late pure/const discovery.

Honza


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug ipa/99835] missed optimization for dead code elimination at -O3 (vs. -O1)
  2021-03-30 17:27 [Bug tree-optimization/99835] New: missed optimization for dead code elimination at -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
  2021-03-31  8:08 ` [Bug ipa/99835] " rguenth at gcc dot gnu.org
@ 2021-03-31  8:14 ` hubicka at ucw dot cz
  2021-03-31  8:17 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: hubicka at ucw dot cz @ 2021-03-31  8:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99835

--- Comment #2 from Jan Hubicka <hubicka at ucw dot cz> ---
> At -O3 the unused 'c' remains.  Likely different (recursive?) inlining makes us
> process a cgraph cycle in different order and thus fail to elide the output
> of 'c' (it's output first at -O3).
> 
> Fixing that would need processing cgraph SCCs with an extra IPA phase in main
> optimization so we get a chance to do extra node removal (maybe order
> the cycles so that functions we can elide - aka static ones - are processed
> last).
That would tamper with optimizations that propagate from callee to
caller during late optimization, like IPA register allocation, stack
alignment propagation or late pure/const discovery.

Honza

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug ipa/99835] missed optimization for dead code elimination at -O3 (vs. -O1)
  2021-03-30 17:27 [Bug tree-optimization/99835] New: missed optimization for dead code elimination at -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
  2021-03-31  8:08 ` [Bug ipa/99835] " rguenth at gcc dot gnu.org
  2021-03-31  8:14 ` hubicka at ucw dot cz
@ 2021-03-31  8:17 ` rguenth at gcc dot gnu.org
  2021-03-31  9:10 ` hubicka at ucw dot cz
  2021-09-25  7:20 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-03-31  8:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99835

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Jan Hubicka from comment #2)
> > At -O3 the unused 'c' remains.  Likely different (recursive?) inlining makes us
> > process a cgraph cycle in different order and thus fail to elide the output
> > of 'c' (it's output first at -O3).
> > 
> > Fixing that would need processing cgraph SCCs with an extra IPA phase in main
> > optimization so we get a chance to do extra node removal (maybe order
> > the cycles so that functions we can elide - aka static ones - are processed
> > last).
> That would tamper with optimizations that propagate from callee to
> caller during late optimization, like IPA register allocation, stack
> alignment propagation or late pure/const discovery.

But inside a SCC the order is arbitrary anyway.  Note I'd only re-order SCCs
and keep the postordering the same otherwise.

> Honza

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug ipa/99835] missed optimization for dead code elimination at -O3 (vs. -O1)
  2021-03-30 17:27 [Bug tree-optimization/99835] New: missed optimization for dead code elimination at -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2021-03-31  8:17 ` rguenth at gcc dot gnu.org
@ 2021-03-31  9:10 ` hubicka at ucw dot cz
  2021-09-25  7:20 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 7+ messages in thread
From: hubicka at ucw dot cz @ 2021-03-31  9:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99835

--- Comment #4 from Jan Hubicka <hubicka at ucw dot cz> ---
> But inside a SCC the order is arbitrary anyway.  Note I'd only re-order SCCs
> and keep the postordering the same otherwise.

We compile leaf functions first to be able to propagated to their
callers.  In order to be able to optimize out functions in case call was
optimized out, we would need to compile in reverse order than we do
now...

Honza

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug ipa/99835] missed optimization for dead code elimination at -O3 (vs. -O1)
  2021-03-30 17:27 [Bug tree-optimization/99835] New: missed optimization for dead code elimination at -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2021-03-31  9:10 ` hubicka at ucw dot cz
@ 2021-09-25  7:20 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-25  7:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99835

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=100036

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Really, same underlying issue as PR 100036.
The late-ness of static-var which allows some non-optimized code to be inlined
and IPA-SRA creates a clone which then no longer is called later on.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-09-25  7:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-30 17:27 [Bug tree-optimization/99835] New: missed optimization for dead code elimination at -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
2021-03-31  8:08 ` [Bug ipa/99835] " rguenth at gcc dot gnu.org
2021-03-31  8:14   ` Jan Hubicka
2021-03-31  8:14 ` hubicka at ucw dot cz
2021-03-31  8:17 ` rguenth at gcc dot gnu.org
2021-03-31  9:10 ` hubicka at ucw dot cz
2021-09-25  7:20 ` pinskia 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).