public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/112859] New: wrong code at -O3 on x86_64-linux-gnu
@ 2023-12-05  8:49 zhendong.su at inf dot ethz.ch
  2023-12-05 13:18 ` [Bug tree-optimization/112859] [12/13/14 Regression] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2023-12-05  8:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112859
           Summary: wrong code at -O3 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/aa8vrex9c

[555] % gcctk -v
Using built-in specs.
COLLECT_GCC=gcctk
COLLECT_LTO_WRAPPER=/local/home/suz/suz-local/software/local/gcc-trunk/bin/../libexec/gcc/x86_64-pc-linux-gnu/14.0.0/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.0 20231205 (experimental) (GCC) 
[556] % 
[556] % gcctk -O2 small.c; ./a.out
[557] % 
[557] % gcctk -O3 small.c
[558] % ./a.out
Aborted
[559] % 
[559] % cat small.c
struct a {
  char b;
  int c;
} f, *i = &f;
static struct a e[4];
int *d, **g = &d;
static int h, j;
int main() {
  for (; h < 1; h++) {
    struct a k = {1, 1};
    for (j = 0; j < 2; j++) {
      *i = e[h];
      e[h] = k;
    }
    *g = 0;
  }
  if (f.c != 1)
    __builtin_abort();
  return 0;
}

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

* [Bug tree-optimization/112859] [12/13/14 Regression] wrong code at -O3 on x86_64-linux-gnu
  2023-12-05  8:49 [Bug tree-optimization/112859] New: wrong code at -O3 on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
@ 2023-12-05 13:18 ` rguenth at gcc dot gnu.org
  2023-12-05 13:53 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-12-05 13:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |x86_64-*-*
            Version|unknown                     |14.0
           Keywords|                            |needs-bisection, wrong-code
            Summary|wrong code at -O3 on        |[12/13/14 Regression] wrong
                   |x86_64-linux-gnu            |code at -O3 on
                   |                            |x86_64-linux-gnu
   Target Milestone|---                         |12.4

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

* [Bug tree-optimization/112859] [12/13/14 Regression] wrong code at -O3 on x86_64-linux-gnu
  2023-12-05  8:49 [Bug tree-optimization/112859] New: wrong code at -O3 on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
  2023-12-05 13:18 ` [Bug tree-optimization/112859] [12/13/14 Regression] " rguenth at gcc dot gnu.org
@ 2023-12-05 13:53 ` rguenth at gcc dot gnu.org
  2023-12-05 13:54 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-12-05 13:53 UTC (permalink / raw)
  To: gcc-bugs

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

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
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=112281
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2023-12-05
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
t.c:9:12: optimized: Loop nest 1 distributed: split to 2 loops and 0 library
calls.

-fno-tree-loop-distribution fixes this

GCC 11 distributes the inner loop, but only splits out the assignment to 'j'
there while with 12+ we distribute away the store to e[h].c.  Looks somewhat
familiar to the other "aggregate copy" case where we have no evolution in
the inner loop.

The critical dependence is

(Data Dep: 
#(Data Ref: 
#  bb: 5 
#  stmt: *i.1_1 = e[h.7_24];
#  ref: e[h.7_24];
#  base_object: e;
#  Access function 0: {h.7_20, +, 1}_1
#)
#(Data Ref: 
#  bb: 5 
#  stmt: e[h.7_24].c = 1;
#  ref: e[h.7_24].c;
#  base_object: e;
#  Access function 0: 32
#  Access function 1: {h.7_20, +, 1}_1
#)
  access_fn_A: {h.7_20, +, 1}_1
  access_fn_B: {h.7_20, +, 1}_1

 (subscript 
  iterations_that_access_an_element_twice_in_A: [0]
  last_conflict: scev_not_known
  iterations_that_access_an_element_twice_in_B: [0]
  last_conflict: scev_not_known
  (Subscript distance: 0 ))
  loop nest: (1 2 )
  distance_vector: 0 0 
  direction_vector:     =    =
)

which is then running into

              /* If the overlap is exact preserve stmt order.  */
              else if (lambda_vector_zerop (DDR_DIST_VECT (ddr, 0),
                                            DDR_NB_LOOPS (ddr)))
                ;

so maybe that special-casing is indeed incorrect, and the special-casing
I added

                  /* When then dependence distance of the innermost common
                     loop of the DRs is zero we have a conflict.  */
                  auto l1 = gimple_bb (DR_STMT (dr1))->loop_father;
                  auto l2 = gimple_bb (DR_STMT (dr2))->loop_father;
                  int idx = index_in_loop_nest (find_common_loop (l1, l2)->num,
                                                DDR_LOOP_NEST (ddr));
                  if (DDR_DIST_VECT (ddr, 0)[idx] == 0)
                    this_dir = 2;

should instead be handled to somehow handle more generally the situation that
two refs conflict in a loop where the refs do not evolve.

Thanks for these testcases btw.

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

* [Bug tree-optimization/112859] [12/13/14 Regression] wrong code at -O3 on x86_64-linux-gnu
  2023-12-05  8:49 [Bug tree-optimization/112859] New: wrong code at -O3 on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
  2023-12-05 13:18 ` [Bug tree-optimization/112859] [12/13/14 Regression] " rguenth at gcc dot gnu.org
  2023-12-05 13:53 ` rguenth at gcc dot gnu.org
@ 2023-12-05 13:54 ` rguenth at gcc dot gnu.org
  2023-12-05 19:14 ` zhendong.su at inf dot ethz.ch
  2023-12-07  0:45 ` [Bug tree-optimization/112859] [12/13/14 Regression] wrong code at -O3 on x86_64-linux-gnu since r12-2097-g9f34b780b0461e sjames at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-12-05 13:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

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

* [Bug tree-optimization/112859] [12/13/14 Regression] wrong code at -O3 on x86_64-linux-gnu
  2023-12-05  8:49 [Bug tree-optimization/112859] New: wrong code at -O3 on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2023-12-05 13:54 ` rguenth at gcc dot gnu.org
@ 2023-12-05 19:14 ` zhendong.su at inf dot ethz.ch
  2023-12-07  0:45 ` [Bug tree-optimization/112859] [12/13/14 Regression] wrong code at -O3 on x86_64-linux-gnu since r12-2097-g9f34b780b0461e sjames at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2023-12-05 19:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Zhendong Su <zhendong.su at inf dot ethz.ch> ---
> Thanks for these testcases btw.

Happy to be of help, Richard. 

And thanks to you folks for the incredible work and dedication!

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

* [Bug tree-optimization/112859] [12/13/14 Regression] wrong code at -O3 on x86_64-linux-gnu since r12-2097-g9f34b780b0461e
  2023-12-05  8:49 [Bug tree-optimization/112859] New: wrong code at -O3 on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2023-12-05 19:14 ` zhendong.su at inf dot ethz.ch
@ 2023-12-07  0:45 ` sjames at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: sjames at gcc dot gnu.org @ 2023-12-07  0:45 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|needs-bisection             |
                 CC|                            |sjames at gcc dot gnu.org
            Summary|[12/13/14 Regression] wrong |[12/13/14 Regression] wrong
                   |code at -O3 on              |code at -O3 on
                   |x86_64-linux-gnu            |x86_64-linux-gnu since
                   |                            |r12-2097-g9f34b780b0461e

--- Comment #3 from Sam James <sjames at gcc dot gnu.org> ---
bisected to r12-2097-g9f34b780b0461e

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

end of thread, other threads:[~2023-12-07  0:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-05  8:49 [Bug tree-optimization/112859] New: wrong code at -O3 on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
2023-12-05 13:18 ` [Bug tree-optimization/112859] [12/13/14 Regression] " rguenth at gcc dot gnu.org
2023-12-05 13:53 ` rguenth at gcc dot gnu.org
2023-12-05 13:54 ` rguenth at gcc dot gnu.org
2023-12-05 19:14 ` zhendong.su at inf dot ethz.ch
2023-12-07  0:45 ` [Bug tree-optimization/112859] [12/13/14 Regression] wrong code at -O3 on x86_64-linux-gnu since r12-2097-g9f34b780b0461e sjames 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).