public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/100051] New: missed optimization for dead code elimination at -Os, -O2 and -O3 (vs. -O1)
@ 2021-04-12 20:15 zhendong.su at inf dot ethz.ch
  2021-04-13  8:09 ` [Bug tree-optimization/100051] " 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-04-12 20:15 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100051
           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: ---

[719] % 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 20210412 (experimental) [master revision
46c47420a5f:66634f1d5eb:8f17d44ad986e0ae7e81c81179463000ee9d7f43] (GCC) 
[720] % 
[720] % gcctk -O1 -S -o O1.s small.c
[721] % gcctk -O3 -S -o O3.s small.c
[722] % 
[722] % wc O1.s O3.s
  56  121  784 O1.s
  68  148  996 O3.s
 124  269 1780 total
[723] % 
[723] % grep foo O1.s
[724] % grep foo O3.s
        call    foo
[725] % 
[725] % cat small.c
extern void foo(void);
int a, c, *f, **d = &f;
char b;
static void e() {
  if ((2 ^ b) == 0)
    foo();
}
int main() {
  if (a) {
    b = 0;
    int *g = &c;
    *g = 0;
    f = *d;
    *d = f;
    e();
  }
  return 0;
}

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

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

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

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

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
The difference is WRT -fstrict-aliasing which forces us to keep a redundant
store:

   b = 0;
   c = 0;
   d.1_2 = d;
   _3 = *d.1_2;
   f = _3;
+  *d.1_2 = _3;
   b.4_10 = b;
   if (b.4_10 == 2)

and this store prevents us from CSEing the load from b with the earlier store
from zero to simplify the test because d could alias b.  It looks like
we fail to make the size argument but eventually because of possible
interposition.  We could also figure the stores redundancy during
disambiguation and ignore it based on that fact.

There is code to do the size based disambiguation but it's fent off via
an earlier

  /* If the alias set for a pointer access is zero all bets are off.  */
  if (base1_alias_set == 0 || base2_alias_set == 0)
    return true;

it's also guarded by -fstrict-aliasing for reasons I do not remember.
The base2_alias_set check was added by Honza recently.  The size check
uses not the access size but the possibly larger access TBAA type size
determining the dynamic type of the indirectly addressed object, we can
probably improve this and use the access size for the !tbaa case here.

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

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

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

--- 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:d1d01a66012a93cc8cb7dafbe1b5ec453ec96b59

commit r12-145-gd1d01a66012a93cc8cb7dafbe1b5ec453ec96b59
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Apr 13 10:12:03 2021 +0200

    tree-optimization/100051 - disambiguate access size vs decl

    This adds disambiguation of the access size vs. the decl size
    in the pointer based vs. decl based disambiguator.  We have
    a TBAA based check like this already but that's fend off when
    seeing alias-sets of zero or when -fno-strict-aliasing is in
    effect.  Also the perceived dynamic type could be smaller than
    the actual access.

    2021-04-13  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/100051
            * tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Add
            disambiguator based on access size vs. decl size.

            * gcc.dg/tree-ssa/ssa-fre-92.c: New testcase.

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

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

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

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

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

end of thread, other threads:[~2021-04-27 10:41 UTC | newest]

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