public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114207] New: Wrong code bug since GCC 12.1
@ 2024-03-02  9:21 congli at smail dot nju.edu.cn
  2024-03-02  9:33 ` [Bug tree-optimization/114207] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: congli at smail dot nju.edu.cn @ 2024-03-02  9:21 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114207
           Summary: Wrong code bug since GCC 12.1
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: congli at smail dot nju.edu.cn
  Target Milestone: ---

The program below shows a wrong code bug, where the correct result should be
"s.a=12, s.b=6" while `-w -O3 -fno-tree-forwprop` prints "s.a=12, s.b=0" or
"s.a=12, s.b=<random>". The bug stems from at least GCC 12.1 to our trunk.

```
#include <stdio.h>
#include <stdint.h>

struct S {
    int a, b;
};

__attribute__((noinline))
void foo (struct S *s) {
    struct S ss = (struct S) {
        .a = s->b,
        .b = s->a
    };
    *s = ss;
}

int main() {
  struct S s = {6, 12};
  foo(&s);
  printf("s.a=%d, s.b=%d\n", s.a, s.b);
  return 0;
}
```

Compiler Explorer: https://gcc.godbolt.org/z/8dbMWjsd8

After checking the assembly, we found that `8(%rsp)` (representing s.b) was not
initialized by the constant `6` while it is printed.

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

* [Bug tree-optimization/114207] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop`
  2024-03-02  9:21 [Bug c/114207] New: Wrong code bug since GCC 12.1 congli at smail dot nju.edu.cn
@ 2024-03-02  9:33 ` pinskia at gcc dot gnu.org
  2024-03-02 17:53 ` [Bug tree-optimization/114207] [12/13/14 Regression] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` since r12-5439 jakub at gcc dot gnu.org
  2024-03-03 13:13 ` hubicka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-02  9:33 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=111613
           Keywords|                            |wrong-code
             Status|UNCONFIRMED                 |NEW
          Component|c                           |tree-optimization
            Summary|Wrong code bug since GCC    |modref gets confused by
                   |12.1                        |vecotorized code ` -O3
                   |                            |-fno-tree-forwprop`
   Target Milestone|---                         |12.4
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-03-02

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

The IR is:
```
  vectp.7_7 = &s_4(D)->b;
  vectp.7_8 = vectp.7_7 + 18446744073709551612;
  vect__1.8_9 = MEM <vector(2) int> [(int *)vectp.7_8];
  vect__2.9_10 = VEC_PERM_EXPR <vect__1.8_9, vect__1.8_9, { 1, 0 }>;
  MEM <vector(2) int> [(int *)s_4(D)] = vect__2.9_10;

```

modref thinks this only reads s->b somehow.

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

* [Bug tree-optimization/114207] [12/13/14 Regression] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` since r12-5439
  2024-03-02  9:21 [Bug c/114207] New: Wrong code bug since GCC 12.1 congli at smail dot nju.edu.cn
  2024-03-02  9:33 ` [Bug tree-optimization/114207] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` pinskia at gcc dot gnu.org
@ 2024-03-02 17:53 ` jakub at gcc dot gnu.org
  2024-03-03 13:13 ` hubicka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-03-02 17:53 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at gcc dot gnu.org,
                   |                            |jakub at gcc dot gnu.org
            Summary|[12/13/14 Regression]       |[12/13/14 Regression]
                   |modref gets confused by     |modref gets confused by
                   |vecotorized code ` -O3      |vecotorized code ` -O3
                   |-fno-tree-forwprop`         |-fno-tree-forwprop` since
                   |                            |r12-5439
           Priority|P3                          |P2

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with r12-5439-g0f5afb626381d19bfced30bc19cf3b03867fa6f5

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

* [Bug tree-optimization/114207] [12/13/14 Regression] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` since r12-5439
  2024-03-02  9:21 [Bug c/114207] New: Wrong code bug since GCC 12.1 congli at smail dot nju.edu.cn
  2024-03-02  9:33 ` [Bug tree-optimization/114207] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` pinskia at gcc dot gnu.org
  2024-03-02 17:53 ` [Bug tree-optimization/114207] [12/13/14 Regression] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` since r12-5439 jakub at gcc dot gnu.org
@ 2024-03-03 13:13 ` hubicka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: hubicka at gcc dot gnu.org @ 2024-03-03 13:13 UTC (permalink / raw)
  To: gcc-bugs

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

Jan Hubicka <hubicka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |hubicka at gcc dot gnu.org

--- Comment #3 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
mine.

The summary is:
  loads:
      Base 0: alias set 1
        Ref 0: alias set 1
          access: Parm 0 param offset:4 offset:0 size:64 max_size:64
  stores:
      Base 0: alias set 1
        Ref 0: alias set 1
          access: Parm 0 param offset:0 offset:0 size:64 max_size:64

while with fwprop we get:
  loads:
      Base 0: alias set 1
        Ref 0: alias set 1
          access: Parm 0 param offset:0 offset:0 size:64 max_size:64
  stores:
      Base 0: alias set 1
        Ref 0: alias set 1
          access: Parm 0 param offset:0 offset:0 size:64 max_size:64

So it seems that offset is misaccounted.

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-02  9:21 [Bug c/114207] New: Wrong code bug since GCC 12.1 congli at smail dot nju.edu.cn
2024-03-02  9:33 ` [Bug tree-optimization/114207] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` pinskia at gcc dot gnu.org
2024-03-02 17:53 ` [Bug tree-optimization/114207] [12/13/14 Regression] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` since r12-5439 jakub at gcc dot gnu.org
2024-03-03 13:13 ` hubicka 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).