public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110410] New: [14 Regression] Different results between -O0 and -O2
@ 2023-06-26  9:38 jwzeng at nuaa dot edu.cn
  2023-06-26 10:11 ` [Bug tree-optimization/110410] " jwzeng at nuaa dot edu.cn
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: jwzeng at nuaa dot edu.cn @ 2023-06-26  9:38 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110410
           Summary: [14 Regression] Different results between -O0 and -O2
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jwzeng at nuaa dot edu.cn
  Target Milestone: ---

The following code snippet:

#include <stdio.h>
int seed;
void hash(int *seed, int v) { *seed ^= v; }
unsigned int var_6 = 1341494070U;
int var_7 = 0;
unsigned short var_8 = 7472;
int var_13 = 518868156U;
unsigned var_17;
#define min(a, b) ((a) < (b) ? (a) : (b))
void test() {
    for (int ii_0 = 0; ii_0 < 20; ++ii_0)
        for (int ii_1 = 0; ii_1 < 10; ++ii_1)
            var_17 = min(var_6 ? var_8 >> (var_13 - 518868145U) : var_7,
1887837879 || 0);
}
int main() {
    test(2062689408U);
    hash(&seed, var_17);
    printf("%d\n", seed);
    return 0;
}

> $ /usr/gcc-trunk/bin/gcc -O0 bug.c; ./a.out
> 1
> $ /usr/gcc-trunk/bin/gcc -O2 bug.c; ./a.out
> 3

When compiled with -O2 or -O3, it prints 3 instead of 1. Earlier GCCs do not
have this bug.

> $ /usr/gcc-trunk/bin/gcc --version
gcc (GCC) 14.0.0 20230619 (experimental) [master r14-1917-gf8e0270272]
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE

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

* [Bug tree-optimization/110410] [14 Regression] Different results between -O0 and -O2
  2023-06-26  9:38 [Bug tree-optimization/110410] New: [14 Regression] Different results between -O0 and -O2 jwzeng at nuaa dot edu.cn
@ 2023-06-26 10:11 ` jwzeng at nuaa dot edu.cn
  2023-06-26 11:37 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jwzeng at nuaa dot edu.cn @ 2023-06-26 10:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jw Zeng <jwzeng at nuaa dot edu.cn> ---
Link to the Compiler Explorer: https://godbolt.org/z/d5v5scnP4

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

* [Bug tree-optimization/110410] [14 Regression] Different results between -O0 and -O2
  2023-06-26  9:38 [Bug tree-optimization/110410] New: [14 Regression] Different results between -O0 and -O2 jwzeng at nuaa dot edu.cn
  2023-06-26 10:11 ` [Bug tree-optimization/110410] " jwzeng at nuaa dot edu.cn
@ 2023-06-26 11:37 ` rguenth at gcc dot gnu.org
  2023-06-26 12:32 ` jwzeng at nuaa dot edu.cn
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-06-26 11:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |needs-bisection, wrong-code
   Target Milestone|---                         |14.0

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
phi-opt again?

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

* [Bug tree-optimization/110410] [14 Regression] Different results between -O0 and -O2
  2023-06-26  9:38 [Bug tree-optimization/110410] New: [14 Regression] Different results between -O0 and -O2 jwzeng at nuaa dot edu.cn
  2023-06-26 10:11 ` [Bug tree-optimization/110410] " jwzeng at nuaa dot edu.cn
  2023-06-26 11:37 ` rguenth at gcc dot gnu.org
@ 2023-06-26 12:32 ` jwzeng at nuaa dot edu.cn
  2023-06-26 15:58 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jwzeng at nuaa dot edu.cn @ 2023-06-26 12:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jw Zeng <jwzeng at nuaa dot edu.cn> ---
(In reply to Richard Biener from comment #2)
> phi-opt again?

Link to the Compiler Explorer:https://godbolt.org/z/EeEqMGnWo

I reduced the code again, I hope it helps. The reduced code is as follows:

#include <stdio.h>

int var_1 = 1;
int var_2 = 0;
unsigned short var_3 = 7472;
int var_4 = 518868156U;
unsigned var_5;
#define min(a, b) ((a) < (b) ? (a) : (b))

int main() {
    var_5 = min(var_1 ? var_3 >> (var_4 - 518868145U) : var_2, 1);
    printf("%d\n", var_5);
    return 0;
}

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

* [Bug tree-optimization/110410] [14 Regression] Different results between -O0 and -O2
  2023-06-26  9:38 [Bug tree-optimization/110410] New: [14 Regression] Different results between -O0 and -O2 jwzeng at nuaa dot edu.cn
                   ` (2 preceding siblings ...)
  2023-06-26 12:32 ` jwzeng at nuaa dot edu.cn
@ 2023-06-26 15:58 ` pinskia at gcc dot gnu.org
  2023-06-26 16:07 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-26 15:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Yes phiopt again:

  _7 = _3 >> _6;
  iftmp.7_27 = (unsigned int) _7;
  _13 = _7 > 0;
  _12 = (unsigned int) _13;
  _11 = _12 | iftmp.7_27;

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

* [Bug tree-optimization/110410] [14 Regression] Different results between -O0 and -O2
  2023-06-26  9:38 [Bug tree-optimization/110410] New: [14 Regression] Different results between -O0 and -O2 jwzeng at nuaa dot edu.cn
                   ` (3 preceding siblings ...)
  2023-06-26 15:58 ` pinskia at gcc dot gnu.org
@ 2023-06-26 16:07 ` pinskia at gcc dot gnu.org
  2023-06-26 21:32 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-26 16:07 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |110252
             Status|UNCONFIRMED                 |NEW
           Keywords|needs-bisection             |missed-optimization
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-06-26

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is basically a dup of bug 110252 as the range of iftmp.7_27 is flow
sensitive here.

BUT there is a missed optimization before hand though:
  # RANGE [irange] unsigned int [0, 0] NONZERO 0x0
  iftmp.7_27 = (unsigned intD.9) _7;

This shows up in dom3. So keeping it open for that case too ...


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110252
[Bug 110252] [14 Regression] Wrong code at -O2/3/s on x86_64-linux-gnu

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

* [Bug tree-optimization/110410] [14 Regression] Different results between -O0 and -O2
  2023-06-26  9:38 [Bug tree-optimization/110410] New: [14 Regression] Different results between -O0 and -O2 jwzeng at nuaa dot edu.cn
                   ` (4 preceding siblings ...)
  2023-06-26 16:07 ` pinskia at gcc dot gnu.org
@ 2023-06-26 21:32 ` pinskia at gcc dot gnu.org
  2023-07-19 16:19 ` pinskia at gcc dot gnu.org
  2023-07-19 16:36 ` [Bug tree-optimization/110410] Missed optimization in DOM with a single value range pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-26 21:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jw Zeng from comment #3)
> (In reply to Richard Biener from comment #2)
> > phi-opt again?
> 
> Link to the Compiler Explorer:https://godbolt.org/z/EeEqMGnWo
> 
> I reduced the code again, I hope it helps. The reduced code is as follows:

This reduced testcase is the same issue except it is dom2 which has the missed
optimization:
Exported global range table:
============================
_3  : [irange] int [0, 65535] NONZERO 0xffff
_7  : [irange] int [0, 65535] NONZERO 0xffff
iftmp.0_16  : [irange] unsigned int [0, 1][2147483648, +INF]
iftmp.7_21  : [irange] unsigned int [0, 0][2147483648, +INF]
iftmp.7_22  : [irange] unsigned int [0, 0] NONZERO 0x0

Note the reason why dom3 is able to figure out:
  # VUSE <.MEM_18(D)>
  var_3.9_9 = var_3;
is the same as var_3.3_2
and not fre3 is because a jump threading is needed to happen before. Once dom3
is already to figure that out, it becomes obvious that is _22 is 0 and such.

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

* [Bug tree-optimization/110410] [14 Regression] Different results between -O0 and -O2
  2023-06-26  9:38 [Bug tree-optimization/110410] New: [14 Regression] Different results between -O0 and -O2 jwzeng at nuaa dot edu.cn
                   ` (5 preceding siblings ...)
  2023-06-26 21:32 ` pinskia at gcc dot gnu.org
@ 2023-07-19 16:19 ` pinskia at gcc dot gnu.org
  2023-07-19 16:36 ` [Bug tree-optimization/110410] Missed optimization in DOM with a single value range pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-19 16:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110410
Bug 110410 depends on bug 110252, which changed state.

Bug 110252 Summary: [14 Regression] Wrong code at -O2/3/s on x86_64-linux-gnu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110252

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

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

* [Bug tree-optimization/110410] Missed optimization in DOM with a single value range
  2023-06-26  9:38 [Bug tree-optimization/110410] New: [14 Regression] Different results between -O0 and -O2 jwzeng at nuaa dot edu.cn
                   ` (6 preceding siblings ...)
  2023-07-19 16:19 ` pinskia at gcc dot gnu.org
@ 2023-07-19 16:36 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-19 16:36 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|14.0                        |---
           Keywords|wrong-code                  |
            Summary|[14 Regression] Different   |Missed optimization in DOM
                   |results between -O0 and -O2 |with a single value range

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The reduced testcase in comment #3 still has the missed optimization so keeping
this open and changing the summary and removing the regression marker.

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

end of thread, other threads:[~2023-07-19 16:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-26  9:38 [Bug tree-optimization/110410] New: [14 Regression] Different results between -O0 and -O2 jwzeng at nuaa dot edu.cn
2023-06-26 10:11 ` [Bug tree-optimization/110410] " jwzeng at nuaa dot edu.cn
2023-06-26 11:37 ` rguenth at gcc dot gnu.org
2023-06-26 12:32 ` jwzeng at nuaa dot edu.cn
2023-06-26 15:58 ` pinskia at gcc dot gnu.org
2023-06-26 16:07 ` pinskia at gcc dot gnu.org
2023-06-26 21:32 ` pinskia at gcc dot gnu.org
2023-07-19 16:19 ` pinskia at gcc dot gnu.org
2023-07-19 16:36 ` [Bug tree-optimization/110410] Missed optimization in DOM with a single value range 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).