public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/115492] New: [15 Regression] wrong code at -O2/O3 when compiled with -fPIC
@ 2024-06-14 14:40 tangyixuan at mail dot dlut.edu.cn
  2024-06-14 23:59 ` [Bug tree-optimization/115492] [15 Regression] wrong code at -O2/O3 pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: tangyixuan at mail dot dlut.edu.cn @ 2024-06-14 14:40 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115492
           Summary: [15 Regression] wrong code at -O2/O3 when compiled
                    with -fPIC
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tangyixuan at mail dot dlut.edu.cn
  Target Milestone: ---

Hi, I find that GCC-15 produces the possible wrong code when compiling the
following code with "-O3 -fPIC". However, GCC-13 could get the correct output
with the same compilation flags.

$ gcc-13 -O3 -fPIC s.c; ./a.out
0
$ gcc -O3 -fPIC s.c; ./a.out
2

$ gcc --version
gcc (GCC) 15.0.0 20240602 (experimental)
Copyright (C) 2024 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.

$ cat s.c

extern int printf(const char *format, ...);
int a = 2, b=0, *c = &a, *d = &a, e=0;
void f() {}
void h(int *k) {
  int ***j;
  if (b) {
    *j = &k;
    ***j;
  }
  f(*k);
  *d = e;
  printf("%d\n",*k);
}
int main() { h(c); }

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

* [Bug tree-optimization/115492] [15 Regression] wrong code at -O2/O3
  2024-06-14 14:40 [Bug tree-optimization/115492] New: [15 Regression] wrong code at -O2/O3 when compiled with -fPIC tangyixuan at mail dot dlut.edu.cn
@ 2024-06-14 23:59 ` pinskia at gcc dot gnu.org
  2024-06-15  0:11 ` sjames at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-14 23:59 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2024-06-14
            Summary|[15 Regression] wrong code  |[15 Regression] wrong code
                   |at -O2/O3 when compiled     |at -O2/O3
                   |with -fPIC                  |
           Keywords|                            |needs-bisection
     Ever confirmed|0                           |1
   Target Milestone|---                         |15.0

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. -fPIC is just forces f to not to be inlined.
Here is a testcase which fails at -O2 but passes at -O0/-O1:
```
int a = 2, b=0, *c = &a, *d = &a, e=0;
[[gnu::noipa]]
void f(int) {}
[[gnu::noinline]]
int h(int *k) {
  int ***j;
  if (b) {
    *j = &k; // Note the unintialized j is used here
             // but since it is conditional and b is always zero, there should
no
             // effect otherwise.
    ***j;
  }
  f(*k);
  *d = e;
  return *k;
}
int main() { if (h(c)) __builtin_abort(); }
```

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

* [Bug tree-optimization/115492] [15 Regression] wrong code at -O2/O3
  2024-06-14 14:40 [Bug tree-optimization/115492] New: [15 Regression] wrong code at -O2/O3 when compiled with -fPIC tangyixuan at mail dot dlut.edu.cn
  2024-06-14 23:59 ` [Bug tree-optimization/115492] [15 Regression] wrong code at -O2/O3 pinskia at gcc dot gnu.org
@ 2024-06-15  0:11 ` sjames at gcc dot gnu.org
  2024-06-15  0:13 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-06-15  0:11 UTC (permalink / raw)
  To: gcc-bugs

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

Sam James <sjames at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sjames at gcc dot gnu.org

--- Comment #2 from Sam James <sjames at gcc dot gnu.org> ---
I'll bisect. I have a few guesses...

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

* [Bug tree-optimization/115492] [15 Regression] wrong code at -O2/O3
  2024-06-14 14:40 [Bug tree-optimization/115492] New: [15 Regression] wrong code at -O2/O3 when compiled with -fPIC tangyixuan at mail dot dlut.edu.cn
  2024-06-14 23:59 ` [Bug tree-optimization/115492] [15 Regression] wrong code at -O2/O3 pinskia at gcc dot gnu.org
  2024-06-15  0:11 ` sjames at gcc dot gnu.org
@ 2024-06-15  0:13 ` pinskia at gcc dot gnu.org
  2024-06-15  1:14 ` [Bug tree-optimization/115492] [15 Regression] wrong code at -O2/O3 since r15-204-g7c469a9fc78550 sjames at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-15  0:13 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |alias

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note I am thinking it was one of the recent aliasing patches from richi which
causes this because adding -fno-strict-aliasing allows the testcase to pass.

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

* [Bug tree-optimization/115492] [15 Regression] wrong code at -O2/O3 since r15-204-g7c469a9fc78550
  2024-06-14 14:40 [Bug tree-optimization/115492] New: [15 Regression] wrong code at -O2/O3 when compiled with -fPIC tangyixuan at mail dot dlut.edu.cn
                   ` (2 preceding siblings ...)
  2024-06-15  0:13 ` pinskia at gcc dot gnu.org
@ 2024-06-15  1:14 ` sjames at gcc dot gnu.org
  2024-06-17  5:34 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-06-15  1:14 UTC (permalink / raw)
  To: gcc-bugs

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

Sam James <sjames at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=100923

--- Comment #4 from Sam James <sjames at gcc dot gnu.org> ---
r15-204-g7c469a9fc78550

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

* [Bug tree-optimization/115492] [15 Regression] wrong code at -O2/O3 since r15-204-g7c469a9fc78550
  2024-06-14 14:40 [Bug tree-optimization/115492] New: [15 Regression] wrong code at -O2/O3 when compiled with -fPIC tangyixuan at mail dot dlut.edu.cn
                   ` (3 preceding siblings ...)
  2024-06-15  1:14 ` [Bug tree-optimization/115492] [15 Regression] wrong code at -O2/O3 since r15-204-g7c469a9fc78550 sjames at gcc dot gnu.org
@ 2024-06-17  5:34 ` rguenth at gcc dot gnu.org
  2024-06-17  7:20 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-17  5:34 UTC (permalink / raw)
  To: gcc-bugs

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

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
             Status|NEW                         |ASSIGNED

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
I will have a look.

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

* [Bug tree-optimization/115492] [15 Regression] wrong code at -O2/O3 since r15-204-g7c469a9fc78550
  2024-06-14 14:40 [Bug tree-optimization/115492] New: [15 Regression] wrong code at -O2/O3 when compiled with -fPIC tangyixuan at mail dot dlut.edu.cn
                   ` (4 preceding siblings ...)
  2024-06-17  5:34 ` rguenth at gcc dot gnu.org
@ 2024-06-17  7:20 ` rguenth at gcc dot gnu.org
  2024-06-17 12:40 ` cvs-commit at gcc dot gnu.org
  2024-06-17 13:16 ` rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-17  7:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
OK, so the issue is that we are entering ao_ref_init_from_vn_reference with
valueized operands and vn_valueize assumes the input is available.

It's quite awkward to force availability here because of how PRE is
integrated with VN here.  I'm going to simply revert the change.

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

* [Bug tree-optimization/115492] [15 Regression] wrong code at -O2/O3 since r15-204-g7c469a9fc78550
  2024-06-14 14:40 [Bug tree-optimization/115492] New: [15 Regression] wrong code at -O2/O3 when compiled with -fPIC tangyixuan at mail dot dlut.edu.cn
                   ` (5 preceding siblings ...)
  2024-06-17  7:20 ` rguenth at gcc dot gnu.org
@ 2024-06-17 12:40 ` cvs-commit at gcc dot gnu.org
  2024-06-17 13:16 ` rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-17 12:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from GCC 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:95bfc6abf378a32e502dca0e2938f94d5b0ab094

commit r15-1374-g95bfc6abf378a32e502dca0e2938f94d5b0ab094
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Jun 17 09:23:25 2024 +0200

    Testcase for PR115492

    This adds a testcase for the PR fixed with reversal of
    r15-204-g7c469a9fc78550.

            PR tree-optimization/115492
            * gcc.dg/torture/pr115492.c: New testcase.

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

* [Bug tree-optimization/115492] [15 Regression] wrong code at -O2/O3 since r15-204-g7c469a9fc78550
  2024-06-14 14:40 [Bug tree-optimization/115492] New: [15 Regression] wrong code at -O2/O3 when compiled with -fPIC tangyixuan at mail dot dlut.edu.cn
                   ` (6 preceding siblings ...)
  2024-06-17 12:40 ` cvs-commit at gcc dot gnu.org
@ 2024-06-17 13:16 ` rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-17 13:16 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
I have reverted the change.

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

end of thread, other threads:[~2024-06-17 13:16 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-14 14:40 [Bug tree-optimization/115492] New: [15 Regression] wrong code at -O2/O3 when compiled with -fPIC tangyixuan at mail dot dlut.edu.cn
2024-06-14 23:59 ` [Bug tree-optimization/115492] [15 Regression] wrong code at -O2/O3 pinskia at gcc dot gnu.org
2024-06-15  0:11 ` sjames at gcc dot gnu.org
2024-06-15  0:13 ` pinskia at gcc dot gnu.org
2024-06-15  1:14 ` [Bug tree-optimization/115492] [15 Regression] wrong code at -O2/O3 since r15-204-g7c469a9fc78550 sjames at gcc dot gnu.org
2024-06-17  5:34 ` rguenth at gcc dot gnu.org
2024-06-17  7:20 ` rguenth at gcc dot gnu.org
2024-06-17 12:40 ` cvs-commit at gcc dot gnu.org
2024-06-17 13:16 ` 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).