public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114864] New: wrong code at -O1 with "-fno-tree-dce -fno-tree-fre" on x86_64-linux-gnu
@ 2024-04-26  9:28 zhendong.su at inf dot ethz.ch
  2024-04-26 14:36 ` [Bug tree-optimization/114864] [12/13/14/15 regression] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2024-04-26  9:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114864
           Summary: wrong code at -O1 with "-fno-tree-dce -fno-tree-fre"
                    on x86_64-linux-gnu
           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: ---

This appears to be a regression from 11.*, and affects 12.* and later. 

Compiler Explorer: https://godbolt.org/z/TbYj469r3

[588] % 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/14.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk/configure --disable-bootstrap
--enable-checking=yes --prefix=/local/suz-local/software/local/gcc-trunk
--enable-sanitizers --enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.1 20240426 (experimental) (GCC) 
[589] % 
[589] % gcctk -O1 small.c; ./a.out
[590] % 
[590] % gcctk -O1 -fno-tree-dce -fno-tree-fre small.c
[591] % ./a.out
Segmentation fault
[592] % 
[592] % cat small.c
struct a {
  int b;
} const c;
void d(const struct a f) {}
void e(const struct a f) {
  f.b == 0 ? 1 : f.b;
  d(f);
}
int main() {
  e(c);
  return 0;
}

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

* [Bug tree-optimization/114864] [12/13/14/15 regression] wrong code at -O1 with "-fno-tree-dce -fno-tree-fre" on x86_64-linux-gnu
  2024-04-26  9:28 [Bug tree-optimization/114864] New: wrong code at -O1 with "-fno-tree-dce -fno-tree-fre" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
@ 2024-04-26 14:36 ` rguenth at gcc dot gnu.org
  2024-04-26 14:40 ` hjl.tools at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-26 14:36 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jamborm at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-04-26
           Priority|P3                          |P2
            Version|unknown                     |14.0
   Target Milestone|---                         |12.4
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
int main ()
{
  <bb 2> [local count: 1073741824]:
  c.b = 0;
  return 0;

}


Confirmed.  It seems we are confused during inlining and substitute
'c' for 'f' because both are readonly.  But the write to f is to an
automatic var and thus not readonly memory.

Note the write to f is introduced by SRA so I think it's SRAs fault:

void e (const struct a f)
 {
+  const int f$b;
   int _1;
   int iftmp.0_4;

   <bb 2> :
-  _1 = f.b;
+  f$b_3 = f.b;
+  _1 = f$b_3;
   if (_1 != 0)
     goto <bb 3>; [INV]
   else
     goto <bb 4>; [INV]

   <bb 3> :
-  iftmp.0_4 = f.b;
+  iftmp.0_4 = f$b_3;

   <bb 4> :
+  f.b = f$b_3;
   d (f);

The store is broken.  I think a readonly aggegate never needs to be
re-materialized as it cannot be changed (do we track possible writes?)

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

* [Bug tree-optimization/114864] [12/13/14/15 regression] wrong code at -O1 with "-fno-tree-dce -fno-tree-fre" on x86_64-linux-gnu
  2024-04-26  9:28 [Bug tree-optimization/114864] New: wrong code at -O1 with "-fno-tree-dce -fno-tree-fre" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
  2024-04-26 14:36 ` [Bug tree-optimization/114864] [12/13/14/15 regression] " rguenth at gcc dot gnu.org
@ 2024-04-26 14:40 ` hjl.tools at gmail dot com
  2024-04-26 15:55 ` ebotcazou at gcc dot gnu.org
  2024-04-26 16:59 ` ebotcazou at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: hjl.tools at gmail dot com @ 2024-04-26 14:40 UTC (permalink / raw)
  To: gcc-bugs

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

H.J. Lu <hjl.tools at gmail dot com> changed:

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

--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
It is caused by r12-434.

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

* [Bug tree-optimization/114864] [12/13/14/15 regression] wrong code at -O1 with "-fno-tree-dce -fno-tree-fre" on x86_64-linux-gnu
  2024-04-26  9:28 [Bug tree-optimization/114864] New: wrong code at -O1 with "-fno-tree-dce -fno-tree-fre" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
  2024-04-26 14:36 ` [Bug tree-optimization/114864] [12/13/14/15 regression] " rguenth at gcc dot gnu.org
  2024-04-26 14:40 ` hjl.tools at gmail dot com
@ 2024-04-26 15:55 ` ebotcazou at gcc dot gnu.org
  2024-04-26 16:59 ` ebotcazou at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2024-04-26 15:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Yes, this is a known issue in SRA, see PR optimization/111873, but it
apparently shows up only with nonsensical combinations of switches so, well...

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

* [Bug tree-optimization/114864] [12/13/14/15 regression] wrong code at -O1 with "-fno-tree-dce -fno-tree-fre" on x86_64-linux-gnu
  2024-04-26  9:28 [Bug tree-optimization/114864] New: wrong code at -O1 with "-fno-tree-dce -fno-tree-fre" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2024-04-26 15:55 ` ebotcazou at gcc dot gnu.org
@ 2024-04-26 16:59 ` ebotcazou at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2024-04-26 16:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Another instance is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100453

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

end of thread, other threads:[~2024-04-26 16:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-26  9:28 [Bug tree-optimization/114864] New: wrong code at -O1 with "-fno-tree-dce -fno-tree-fre" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
2024-04-26 14:36 ` [Bug tree-optimization/114864] [12/13/14/15 regression] " rguenth at gcc dot gnu.org
2024-04-26 14:40 ` hjl.tools at gmail dot com
2024-04-26 15:55 ` ebotcazou at gcc dot gnu.org
2024-04-26 16:59 ` ebotcazou 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).