public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/114386] New: [10/11/12 Regression] Miscompile at -O1
@ 2024-03-18 21:19 patrick at rivosinc dot com
  2024-03-18 21:25 ` [Bug tree-optimization/114386] [11/12 " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: patrick at rivosinc dot com @ 2024-03-18 21:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114386
           Summary: [10/11/12 Regression] Miscompile at -O1
           Product: gcc
           Version: 12.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: patrick at rivosinc dot com
  Target Milestone: ---

Testcase:
int printf(const char *, ...);
_Bool a, c = 1;
int b, d;
int main() {
  _Bool g = c;
  d = !a ? ({ c > a ? c : a; }) : 0;
  printf("%x\n", d);
}

Commands:
> gcc -O0 red.c -o red.o
> ./red.o
0

> gcc -O1 red.c -o red.o
> ./red.o
1

> gcc -O2 red.c -o red.o
> ./red.o
0

> gcc -O3 red.c -o red.o
> ./red.o
1

Tested/discovered on x86 - gcc v11.4.0.
Issue is not present when targeting risc-v.

Godbolt shows it's a regression starting at 10.1 (with -O1) and resolved as of
13.1.

Godbolt: https://godbolt.org/z/q4P9xs5dx

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

* [Bug tree-optimization/114386] [11/12 Regression] Miscompile at -O1
  2024-03-18 21:19 [Bug target/114386] New: [10/11/12 Regression] Miscompile at -O1 patrick at rivosinc dot com
@ 2024-03-18 21:25 ` pinskia at gcc dot gnu.org
  2024-03-18 21:31 ` [Bug tree-optimization/114386] [11/12/13 " pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-18 21:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
   Target Milestone|---                         |11.5
          Component|target                      |tree-optimization
      Known to fail|                            |13.1.0
            Summary|[10/11/12 Regression]       |[11/12 Regression]
                   |Miscompile at -O1           |Miscompile at -O1

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

* [Bug tree-optimization/114386] [11/12/13 Regression] Miscompile at -O1
  2024-03-18 21:19 [Bug target/114386] New: [10/11/12 Regression] Miscompile at -O1 patrick at rivosinc dot com
  2024-03-18 21:25 ` [Bug tree-optimization/114386] [11/12 " pinskia at gcc dot gnu.org
@ 2024-03-18 21:31 ` pinskia at gcc dot gnu.org
  2024-03-18 21:36 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-18 21:31 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[11/12 Regression]          |[11/12/13 Regression]
                   |Miscompile at -O1           |Miscompile at -O1
   Last reconfirmed|                            |2024-03-18
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually this still fails in GCC 13 with a slightly different testcase:
```
_Bool a, c = 1;
int b, d;
int main() {
  _Bool g = c;
  d = !a ? ({ c > a ? c : a; }) : 0;
  __builtin_printf("%x, %x\n", d, (int)g);
}
```

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

* [Bug tree-optimization/114386] [11/12/13 Regression] Miscompile at -O1
  2024-03-18 21:19 [Bug target/114386] New: [10/11/12 Regression] Miscompile at -O1 patrick at rivosinc dot com
  2024-03-18 21:25 ` [Bug tree-optimization/114386] [11/12 " pinskia at gcc dot gnu.org
  2024-03-18 21:31 ` [Bug tree-optimization/114386] [11/12/13 " pinskia at gcc dot gnu.org
@ 2024-03-18 21:36 ` pinskia at gcc dot gnu.org
  2024-03-18 21:44 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-18 21:36 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org
      Known to work|                            |14.0
             Status|NEW                         |ASSIGNED

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
PHIOPT goes from:
```
  if (a.1_1 != 0)
    goto <bb 4>; [INV]
  else
    goto <bb 3>; [INV]

  <bb 3> :
  _5 = MAX_EXPR <a.1_1, g_10>;
  iftmp.0_12 = (int) _5;

  <bb 4> :
  # iftmp.0_8 = PHI <iftmp.0_12(3), 0(2)>
```

to:
```
  _5 = MAX_EXPR <a.1_1, g_10>;
  iftmp.0_8 = 0;
```

Due to:
```
PHI iftmp.0_8 changed to factor conversion out from COND_EXPR.
```

Which seems not to be done on the trunk ...

Mine due it being phiopt.

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

* [Bug tree-optimization/114386] [11/12/13 Regression] Miscompile at -O1
  2024-03-18 21:19 [Bug target/114386] New: [10/11/12 Regression] Miscompile at -O1 patrick at rivosinc dot com
                   ` (2 preceding siblings ...)
  2024-03-18 21:36 ` pinskia at gcc dot gnu.org
@ 2024-03-18 21:44 ` pinskia at gcc dot gnu.org
  2024-03-18 21:55 ` patrick at rivosinc dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-18 21:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note the reason why it might work on the trunk is due to replacement of
`MAX_EXPR <c.0_1, a.2_2>` with `c.0_1 | a.2_2` so it might be a latent bug
still on the trunk ...

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

* [Bug tree-optimization/114386] [11/12/13 Regression] Miscompile at -O1
  2024-03-18 21:19 [Bug target/114386] New: [10/11/12 Regression] Miscompile at -O1 patrick at rivosinc dot com
                   ` (3 preceding siblings ...)
  2024-03-18 21:44 ` pinskia at gcc dot gnu.org
@ 2024-03-18 21:55 ` patrick at rivosinc dot com
  2024-03-18 21:57 ` pinskia at gcc dot gnu.org
  2024-03-18 22:01 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: patrick at rivosinc dot com @ 2024-03-18 21:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Patrick O'Neill <patrick at rivosinc dot com> ---
(In reply to Patrick O'Neill from comment #0)
> ...
> Issue is not present when targeting risc-v.

This was in reference to tip-of-tree gcc - forgot to update this when I
determined the upper bound of the regression. RISC-V is also likely affected in
version 10/latent. Also forgot to mention - found via fuzzer.

Thanks for the quick triage as always Andrew.

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

* [Bug tree-optimization/114386] [11/12/13 Regression] Miscompile at -O1
  2024-03-18 21:19 [Bug target/114386] New: [10/11/12 Regression] Miscompile at -O1 patrick at rivosinc dot com
                   ` (4 preceding siblings ...)
  2024-03-18 21:55 ` patrick at rivosinc dot com
@ 2024-03-18 21:57 ` pinskia at gcc dot gnu.org
  2024-03-18 22:01 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-18 21:57 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Yes this turns out to be a dup of bug 111331 which is already fixed on the GCC
13 branch .

Tested the GCC 13 branch with revision right before
r13-7928-gcda1992a56779e5c60a70f251542a6f662fdfa60 and it and it was broken
before but it is working afterwards.

This is a latent bug for a few years now even.

*** This bug has been marked as a duplicate of bug 111331 ***

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

* [Bug tree-optimization/114386] [11/12/13 Regression] Miscompile at -O1
  2024-03-18 21:19 [Bug target/114386] New: [10/11/12 Regression] Miscompile at -O1 patrick at rivosinc dot com
                   ` (5 preceding siblings ...)
  2024-03-18 21:57 ` pinskia at gcc dot gnu.org
@ 2024-03-18 22:01 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-18 22:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note after my r13-7928-gcda1992a56779e5c60a70f251542a6f662fdfa60 patch we get
from phiopt:
```
  if (a.1_1 != 0)
    goto <bb 4>; [50.00%]
  else
    goto <bb 3>; [50.00%]

  <bb 3> [local count: 536870913]:
  _3 = MAX_EXPR <a.1_1, g_7>;

  <bb 4> [local count: 1073741824]:
  # _2 = PHI <_3(3), 0(2)>

```

Which is correct.

And then later on we get:
```
  if (a.1_1 != 0)
    goto <bb 3>; [50.00%]
  else
    goto <bb 4>; [50.00%]

  <bb 3> [local count: 536870912]:

  <bb 4> [local count: 1073741824]:
  # _2 = PHI <g_7(2), 0(3)>

````

Note the trunk we get finally:
```
  _10 = ~a.1_1;
  _11 = g_6 & _10;
```
Which is the best (well really `a < g` but that is a different known issue).

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

end of thread, other threads:[~2024-03-18 22:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-18 21:19 [Bug target/114386] New: [10/11/12 Regression] Miscompile at -O1 patrick at rivosinc dot com
2024-03-18 21:25 ` [Bug tree-optimization/114386] [11/12 " pinskia at gcc dot gnu.org
2024-03-18 21:31 ` [Bug tree-optimization/114386] [11/12/13 " pinskia at gcc dot gnu.org
2024-03-18 21:36 ` pinskia at gcc dot gnu.org
2024-03-18 21:44 ` pinskia at gcc dot gnu.org
2024-03-18 21:55 ` patrick at rivosinc dot com
2024-03-18 21:57 ` pinskia at gcc dot gnu.org
2024-03-18 22:01 ` 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).