public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/95295] New: g++ produces incorrect code with -O3 for loops
@ 2020-05-23 21:56 vsevolod.livinskij at frtk dot ru
  2020-05-25  7:27 ` [Bug tree-optimization/95295] " rguenth at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: vsevolod.livinskij at frtk dot ru @ 2020-05-23 21:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95295
           Summary: g++ produces incorrect code with -O3 for loops
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vsevolod.livinskij at frtk dot ru
  Target Milestone: ---

Error:
>$ g++ func.cpp driver.cpp -O0 && ./a.out 
1
>$ g++ func.cpp driver.cpp -O3 && ./a.out 
0

Reproducer:
func.cpp
extern int var_4, a;
extern unsigned var_9;
extern short arr_272[];
void test() {
  for (int b = 0; b < 9; b++)
    for (int c = 0; c < 9; c += 4) {
      arr_272[c] = var_9 ? var_4 : 0;
      a = 0;
    }
}

driver.cpp
#include <stdio.h>
unsigned long long a;
int var_4 = 1;
short var_9 = 8;
short arr_272[20];
void test();
int main() {
  test();
  printf("%d\n", arr_272[4]);
}

GCC version:
11.0.0 (bcb63eb2cbd3caf212b9cf42d8c218c09dc6ff8b)

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

* [Bug tree-optimization/95295] g++ produces incorrect code with -O3 for loops
  2020-05-23 21:56 [Bug tree-optimization/95295] New: g++ produces incorrect code with -O3 for loops vsevolod.livinskij at frtk dot ru
@ 2020-05-25  7:27 ` rguenth at gcc dot gnu.org
  2020-05-25  8:24 ` rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-05-25  7:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2020-05-25
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed, mine.

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

* [Bug tree-optimization/95295] g++ produces incorrect code with -O3 for loops
  2020-05-23 21:56 [Bug tree-optimization/95295] New: g++ produces incorrect code with -O3 for loops vsevolod.livinskij at frtk dot ru
  2020-05-25  7:27 ` [Bug tree-optimization/95295] " rguenth at gcc dot gnu.org
@ 2020-05-25  8:24 ` rguenth at gcc dot gnu.org
  2020-05-25  9:31 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-05-25  8:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
*** Bug 95283 has been marked as a duplicate of this bug. ***

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

* [Bug tree-optimization/95295] g++ produces incorrect code with -O3 for loops
  2020-05-23 21:56 [Bug tree-optimization/95295] New: g++ produces incorrect code with -O3 for loops vsevolod.livinskij at frtk dot ru
  2020-05-25  7:27 ` [Bug tree-optimization/95295] " rguenth at gcc dot gnu.org
  2020-05-25  8:24 ` rguenth at gcc dot gnu.org
@ 2020-05-25  9:31 ` rguenth at gcc dot gnu.org
  2020-05-25 11:39 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-05-25  9:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
*** Bug 95281 has been marked as a duplicate of this bug. ***

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

* [Bug tree-optimization/95295] g++ produces incorrect code with -O3 for loops
  2020-05-23 21:56 [Bug tree-optimization/95295] New: g++ produces incorrect code with -O3 for loops vsevolod.livinskij at frtk dot ru
                   ` (2 preceding siblings ...)
  2020-05-25  9:31 ` rguenth at gcc dot gnu.org
@ 2020-05-25 11:39 ` cvs-commit at gcc dot gnu.org
  2020-05-25 11:40 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-25 11:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS 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:4acca1c0635dfa43cd8c4bfe2b22e17909fc23a3

commit r11-609-g4acca1c0635dfa43cd8c4bfe2b22e17909fc23a3
Author: Richard Biener <rguenther@suse.de>
Date:   Mon May 25 10:09:44 2020 +0200

    tree-optimization/95295 - fix wrong-code with SM

    We failed to compare the rematerialized store values when merging
    paths after walking PHIs.

    2020-05-25  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/95295
            * tree-ssa-loop-im.c (sm_seq_valid_bb): Compare remat stores
            RHSes and drop to full sm_other if they are not equal.

            * gcc.dg/torture/pr95295-1.c: New testcase.
            * gcc.dg/torture/pr95295-2.c: Likewise.
            * gcc.dg/torture/pr95283.c: Likewise.

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

* [Bug tree-optimization/95295] g++ produces incorrect code with -O3 for loops
  2020-05-23 21:56 [Bug tree-optimization/95295] New: g++ produces incorrect code with -O3 for loops vsevolod.livinskij at frtk dot ru
                   ` (3 preceding siblings ...)
  2020-05-25 11:39 ` cvs-commit at gcc dot gnu.org
@ 2020-05-25 11:40 ` rguenth at gcc dot gnu.org
  2020-05-27  1:29 ` vsevolod.livinskij at frtk dot ru
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-05-25 11:40 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.

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

* [Bug tree-optimization/95295] g++ produces incorrect code with -O3 for loops
  2020-05-23 21:56 [Bug tree-optimization/95295] New: g++ produces incorrect code with -O3 for loops vsevolod.livinskij at frtk dot ru
                   ` (4 preceding siblings ...)
  2020-05-25 11:40 ` rguenth at gcc dot gnu.org
@ 2020-05-27  1:29 ` vsevolod.livinskij at frtk dot ru
  2020-05-27 11:07 ` rguenther at suse dot de
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: vsevolod.livinskij at frtk dot ru @ 2020-05-27  1:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Vsevolod Livinskiy <vsevolod.livinskij at frtk dot ru> ---
Thank you for such a quick fix!

Sorry about duplicates, I saw different assert messages and thought that they
were different bugs.

I still can see ICE in hoist_memory_references (bug 95283) on trunk. I've
attached the reproducer below.

Please let me know if it is a different bug, and I'll create another bug
report.

Error:
>$ g++ -c -O3 func.cpp
during GIMPLE pass: lim
func.cpp: In function ‘void test()’:
func.cpp:5:6: internal compiler error: in hoist_memory_references, at
tree-ssa-loop-im.c:2615
    5 | void test() {
      |      ^~~~
0x82318c hoist_memory_references
        gcc_src/gcc/tree-ssa-loop-im.c:2615
0x82318c store_motion_loop
        gcc_src/gcc/tree-ssa-loop-im.c:2912
0x123853a do_store_motion
        gcc_src/gcc/tree-ssa-loop-im.c:2937
0x123853a tree_ssa_lim
        gcc_src/gcc/tree-ssa-loop-im.c:3156
0x123853a execute
        gcc_src/gcc/tree-ssa-loop-im.c:3206

Reproducer:
extern short var_15, var_20;
extern int var_18, var_21, var_23;
extern bool arr_2[];
extern long arr_3[];
void test() {
  var_20 = 1;
  for (int a = 0; a < 12; a += 2)
    for (short b = 0; b < 8; b += 2) {
      arr_2[b] = var_21 = var_18 ? var_15 : 0;
      arr_3[b] = 8569;
    }
  var_23 = -1096835496;
}

GCC version:
11.0.0 (adad99eb906164af7d2b398ad7e430aebe3adeb4)

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

* [Bug tree-optimization/95295] g++ produces incorrect code with -O3 for loops
  2020-05-23 21:56 [Bug tree-optimization/95295] New: g++ produces incorrect code with -O3 for loops vsevolod.livinskij at frtk dot ru
                   ` (5 preceding siblings ...)
  2020-05-27  1:29 ` vsevolod.livinskij at frtk dot ru
@ 2020-05-27 11:07 ` rguenther at suse dot de
  2020-05-27 12:57 ` cvs-commit at gcc dot gnu.org
  2020-06-06 19:26 ` gsocshubham at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: rguenther at suse dot de @ 2020-05-27 11:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from rguenther at suse dot de <rguenther at suse dot de> ---
On Wed, 27 May 2020, vsevolod.livinskij at frtk dot ru wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95295
> 
> --- Comment #6 from Vsevolod Livinskiy <vsevolod.livinskij at frtk dot ru> ---
> Thank you for such a quick fix!
> 
> Sorry about duplicates, I saw different assert messages and thought that they
> were different bugs.
> 
> I still can see ICE in hoist_memory_references (bug 95283) on trunk. I've
> attached the reproducer below.
> 
> Please let me know if it is a different bug, and I'll create another bug
> report.

Thanks for the report - I have a patch, no need for another bug report.

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

* [Bug tree-optimization/95295] g++ produces incorrect code with -O3 for loops
  2020-05-23 21:56 [Bug tree-optimization/95295] New: g++ produces incorrect code with -O3 for loops vsevolod.livinskij at frtk dot ru
                   ` (6 preceding siblings ...)
  2020-05-27 11:07 ` rguenther at suse dot de
@ 2020-05-27 12:57 ` cvs-commit at gcc dot gnu.org
  2020-06-06 19:26 ` gsocshubham at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-27 12:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS 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:6c8e16aea85286721eb5689f9bcae09d36003cb1

commit r11-660-g6c8e16aea85286721eb5689f9bcae09d36003cb1
Author: Richard Biener <rguenther@suse.de>
Date:   Wed May 27 13:05:07 2020 +0200

    tree-optimization/95295 - fix sinking after path merging in new SM code

    This fixes a missed sinking of remat stores across unrelated stores
    after merging from different paths.

    2020-05-27  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/95295
            * tree-ssa-loop-im.c (sm_seq_valid_bb): Fix sinking after
            merging stores from paths.

            * gcc.dg/torture/pr95295-3.c: New testcase.

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

* [Bug tree-optimization/95295] g++ produces incorrect code with -O3 for loops
  2020-05-23 21:56 [Bug tree-optimization/95295] New: g++ produces incorrect code with -O3 for loops vsevolod.livinskij at frtk dot ru
                   ` (7 preceding siblings ...)
  2020-05-27 12:57 ` cvs-commit at gcc dot gnu.org
@ 2020-06-06 19:26 ` gsocshubham at gmail dot com
  8 siblings, 0 replies; 10+ messages in thread
From: gsocshubham at gmail dot com @ 2020-06-06 19:26 UTC (permalink / raw)
  To: gcc-bugs

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

Shubham Narlawar <gsocshubham at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gsocshubham at gmail dot com

--- Comment #9 from Shubham Narlawar <gsocshubham at gmail dot com> ---

I found the ICE - "internal compiler error: in hoist_memory_references, at
tree-ssa-loop-im.c:2615" with below testcase when compiled with -Og on trunk.
The testcase is obtained by fuzzing function attributes in Csmith - 


--------------------------Testcase---------------------------------------

a, b, c, d, f;
**e;
g() __attribute__((optimize("Ofast")));
g(h) {
  int *i = &a;
  for (; f;) {
    c = 5;
    for (; c; c--) {
      char *j = &b;
      **e = (h && d) == a;
      *i = 0;
      *j = 0;
    }
  }
}

-------------------------------------------------------------------------


I see above ICE has been fixed now.

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

end of thread, other threads:[~2020-06-06 19:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-23 21:56 [Bug tree-optimization/95295] New: g++ produces incorrect code with -O3 for loops vsevolod.livinskij at frtk dot ru
2020-05-25  7:27 ` [Bug tree-optimization/95295] " rguenth at gcc dot gnu.org
2020-05-25  8:24 ` rguenth at gcc dot gnu.org
2020-05-25  9:31 ` rguenth at gcc dot gnu.org
2020-05-25 11:39 ` cvs-commit at gcc dot gnu.org
2020-05-25 11:40 ` rguenth at gcc dot gnu.org
2020-05-27  1:29 ` vsevolod.livinskij at frtk dot ru
2020-05-27 11:07 ` rguenther at suse dot de
2020-05-27 12:57 ` cvs-commit at gcc dot gnu.org
2020-06-06 19:26 ` gsocshubham at gmail dot com

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).