public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/99793] New: missed optimization for dead code elimination at -Os, -O2 and -O3 (vs. -O1)
@ 2021-03-26 15:04 zhendong.su at inf dot ethz.ch
  2021-03-29  7:35 ` [Bug tree-optimization/99793] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2021-03-26 15:04 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99793
           Summary: missed optimization for dead code elimination at -Os,
                    -O2 and -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: ---

[610] % 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 20210326 (experimental) [master revision
9d45e848d02:ca344bbd24f:6081d8994ed1a0aef6b7f5fb34f091faa3580416] (GCC) 
[611] % 
[611] % gcctk -O1 -S -o O1.s small.c
[612] % gcctk -O3 -S -o O3.s small.c
[613] % 
[613] % wc O1.s O3.s
 17  38 365 O1.s
 37  78 633 O3.s
 54 116 998 total
[614] % 
[614] % grep foo O1.s
[615] % grep foo O3.s
        call    foo
[616] % 
[616] % cat small.c
extern void foo(void);
static int a, *b = &a, c, *d = &c;
int main() {
  int **e = &d;
  if (!((unsigned)((*e = d) == 0) - (*b = 1)))
    foo();
  return 0;
}

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

* [Bug tree-optimization/99793] missed optimization for dead code elimination at -Os, -O2 and -O3 (vs. -O1)
  2021-03-26 15:04 [Bug tree-optimization/99793] New: missed optimization for dead code elimination at -Os, -O2 and -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
@ 2021-03-29  7:35 ` rguenth at gcc dot gnu.org
  2021-09-28 10:50 ` cvs-commit at gcc dot gnu.org
  2021-09-28 10:50 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-03-29  7:35 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
            Version|unknown                     |11.0
   Last reconfirmed|                            |2021-03-29
           Keywords|                            |missed-optimization

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
So the difference is -fstrict-aliasing which causes us to not elide the
redundant store to 'd' which in turn makes us fail to promote 'd' read-only:

 Value numbering stmt = d = d.2_2;
-Store matched earlier value, value numbering store vdefs to matching vuses.
-Setting value number of .MEM_9 to .MEM_8 (changed)
-Deleted redundant store d = d.2_2;
+No store match
+Value numbering store d to d.2_2
+Setting value number of .MEM_9 to .MEM_9 (changed)

and the issue is that we "optimize" part of the walking with recording
last_vuse and using that vuse to insert the preceeding load into the
hashtables but since the walking is different for redundant store
detection (no TBAA), it cannot walk that far (beyond the non-TBAA
aliasing store to *b) and thus it cannot find the hashtable entry of
the d.2_2 = d load.  The last-vuse trick is poor-mans "PRE" - I do remember
experimenting with inserting both last and original vuse exprs but I do not
remember the outcome.

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

* [Bug tree-optimization/99793] missed optimization for dead code elimination at -Os, -O2 and -O3 (vs. -O1)
  2021-03-26 15:04 [Bug tree-optimization/99793] New: missed optimization for dead code elimination at -Os, -O2 and -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
  2021-03-29  7:35 ` [Bug tree-optimization/99793] " rguenth at gcc dot gnu.org
@ 2021-09-28 10:50 ` cvs-commit at gcc dot gnu.org
  2021-09-28 10:50 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-28 10:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:34b1e44e166c58df20a15cb35b6cc8d4d299d415

commit r12-3919-g34b1e44e166c58df20a15cb35b6cc8d4d299d415
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Sep 28 12:48:50 2021 +0200

    tree-optimization/99793 - testcase for the PR

    This adds a testcase for the PR which was fixed with the fix for
    PR100112.

    2021-09-28  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/99793
            * gcc.dg/tree-ssa/pr99793.c: New testcase.

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

* [Bug tree-optimization/99793] missed optimization for dead code elimination at -Os, -O2 and -O3 (vs. -O1)
  2021-03-26 15:04 [Bug tree-optimization/99793] New: missed optimization for dead code elimination at -Os, -O2 and -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
  2021-03-29  7:35 ` [Bug tree-optimization/99793] " rguenth at gcc dot gnu.org
  2021-09-28 10:50 ` cvs-commit at gcc dot gnu.org
@ 2021-09-28 10:50 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-09-28 10:50 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |12.0

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed for GCC 12.

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

end of thread, other threads:[~2021-09-28 10:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-26 15:04 [Bug tree-optimization/99793] New: missed optimization for dead code elimination at -Os, -O2 and -O3 (vs. -O1) zhendong.su at inf dot ethz.ch
2021-03-29  7:35 ` [Bug tree-optimization/99793] " rguenth at gcc dot gnu.org
2021-09-28 10:50 ` cvs-commit at gcc dot gnu.org
2021-09-28 10:50 ` rguenth 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).