public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/100080] New: missed optimization for dead code elimination at -O3 (vs. -O2)
@ 2021-04-14 14:14 zhendong.su at inf dot ethz.ch
  2021-04-15  6:43 ` [Bug rtl-optimization/100080] " 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-14 14:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100080
           Summary: missed optimization for dead code elimination at -O3
                    (vs. -O2)
           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: ---

[604] % 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 20210414 (experimental) [master revision
006783f4b16:29da9c11552:0589be0c59767cf4cbb0ef0e7d918cf6aa3d606c] (GCC) 
[605] % 
[605] % gcctk -O2 -S -o O2.s small.c
[606] % gcctk -O3 -S -o O3.s small.c
[607] % 
[607] % wc O2.s O3.s
  68  147  999 O2.s
  95  202 1373 O3.s
 163  349 2372 total
[608] % 
[608] % grep foo O2.s
[609] % grep foo O3.s
        call    foo
[610] % 
[610] % cat small.c
extern void foo(void);
int a, b, d, f;
static unsigned c;
void e(int g, int *k) {
  int h, *i = &b, *j = &b;
  *i = g;
  c = &b == i;
  d = c >= (*j = b | *k) && b & (*i == 0);
  h = a ? 0 : d;
  if (h)
    foo();
}
int main() {
  while (f) {
    int l;
    e(1, &l);
  }
  return 0;
}

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

* [Bug rtl-optimization/100080] missed optimization for dead code elimination at -O3 (vs. -O2)
  2021-04-14 14:14 [Bug tree-optimization/100080] New: missed optimization for dead code elimination at -O3 (vs. -O2) zhendong.su at inf dot ethz.ch
@ 2021-04-15  6:43 ` rguenth at gcc dot gnu.org
  2023-06-02  5:03 ` pinskia at gcc dot gnu.org
  2023-08-18  6:52 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-04-15  6:43 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-04-15
             Status|UNCONFIRMED                 |NEW
          Component|tree-optimization           |rtl-optimization
            Version|unknown                     |11.0

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  At -O2 combine manages to drop the call to foo () (indirectly), at
-O3 it does not.  There's not much difference on the GIMPLE level

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

* [Bug rtl-optimization/100080] missed optimization for dead code elimination at -O3 (vs. -O2)
  2021-04-14 14:14 [Bug tree-optimization/100080] New: missed optimization for dead code elimination at -O3 (vs. -O2) zhendong.su at inf dot ethz.ch
  2021-04-15  6:43 ` [Bug rtl-optimization/100080] " rguenth at gcc dot gnu.org
@ 2023-06-02  5:03 ` pinskia at gcc dot gnu.org
  2023-08-18  6:52 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-02  5:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #1)
> Confirmed.  At -O2 combine manages to drop the call to foo () (indirectly),
> at -O3 it does not.  There's not much difference on the GIMPLE level

For the gimple level it comes down to:
  _5 = (unsigned int) l_20(D);
  if (_5 > 1)
    goto <bb 5>; [50.00%]
  else
    goto <bb 6>; [50.00%]

What should we do there, l_20(D) is definitely uninitialized?
We even get a warning about it:

In function 'e',
    inlined from 'main' at <source>:17:5:
<source>:9:20: warning: 'l' may be used uninitialized [-Wmaybe-uninitialized]
    9 |   d = c >= (*j = b | *k) && b & (*i == 0);
      |                  ~~^~~~
<source>: In function 'main':
<source>:16:9: note: 'l' was declared here
   16 |     int l;
      |         ^

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

* [Bug rtl-optimization/100080] missed optimization for dead code elimination at -O3 (vs. -O2)
  2021-04-14 14:14 [Bug tree-optimization/100080] New: missed optimization for dead code elimination at -O3 (vs. -O2) zhendong.su at inf dot ethz.ch
  2021-04-15  6:43 ` [Bug rtl-optimization/100080] " rguenth at gcc dot gnu.org
  2023-06-02  5:03 ` pinskia at gcc dot gnu.org
@ 2023-08-18  6:52 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-18  6:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I am thinking we should mark this as won't fix.
In VRP2 we have:
    <bb 4> [local count: 105119324]:
    _7 = l_20(D) | 1;
    _8 = (unsigned int) _7;
    if (_8 <= 1)
      goto <bb 6>; [41.00%]
    else
      goto <bb 13>; [59.00%]

...
4->6  (T) _7 :  [irange] int [0, 1] MASK 0x1 VALUE 0x0
4->6  (T) _8 :  [irange] unsigned int [0, 1]
4->6  (T) l_20(D) :     [irange] UNDEFINED
...
=========== BB 6 ============
Imports: l_20(D)  
Exports: _5  l_20(D)  
         _5 : l_20(D)(I)  
_7      [irange] int [0, 1] MASK 0x1 VALUE 0x0
l_20(D) [irange] UNDEFINED
    <bb 6> [local count: 43098922]:
    _5 = (unsigned int) l_20(D);
    b = _7;
    if (_5 > 1)
      goto <bb 14>; [37.49%]
    else
      goto <bb 15>; [62.51%]

We techincally could have [0,1] as the range for l_20(D) on the edge 4->6
And then that if goes away.

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

end of thread, other threads:[~2023-08-18  6:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-14 14:14 [Bug tree-optimization/100080] New: missed optimization for dead code elimination at -O3 (vs. -O2) zhendong.su at inf dot ethz.ch
2021-04-15  6:43 ` [Bug rtl-optimization/100080] " rguenth at gcc dot gnu.org
2023-06-02  5:03 ` pinskia at gcc dot gnu.org
2023-08-18  6:52 ` 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).