public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/114800] New: redundant set-zero when initiate a struct
@ 2024-04-22  8:27 absoler at smail dot nju.edu.cn
  2024-04-22  9:10 ` [Bug rtl-optimization/114800] " xry111 at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: absoler at smail dot nju.edu.cn @ 2024-04-22  8:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114800
           Summary: redundant set-zero when initiate a struct
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: absoler at smail dot nju.edu.cn
  Target Milestone: ---

I found a weird case that
```
struct thresh_restart {
        int             *f0;
        int                     f1;
        int                     f2;
        int                     f3;
};

int arr[10];
void __attribute__((noinline)) foo(struct thresh_restart *p) {
    arr[0] = p->f3;
    arr[1] = p->f1;
}

void func(int *b) {
    struct thresh_restart tr = {
        .f0 = b,
        .f1 = 1,
        .f2     = 2,
        .f3     = 3,
    };
    foo(&tr);
}

```

such code is compiled as: (gcc-13.2.0 -O2, regression [11/12/13/trunk])
https://godbolt.org/z/rb4o6xc7E
```
func(int*):
 sub    $0x28,%rsp
 pxor   %xmm0,%xmm0
 mov    %rsp,%rdi
 movaps %xmm0,(%rsp)
 movq   $0x0,0x10(%rsp)   # redundancy
 movl   $0x1,0x8(%rsp)
 movl   $0x3,0x10(%rsp)
 call   401120 <foo(thresh_restart*)>
 add    $0x28,%rsp
 ret
```

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

* [Bug rtl-optimization/114800] redundant set-zero when initiate a struct
  2024-04-22  8:27 [Bug rtl-optimization/114800] New: redundant set-zero when initiate a struct absoler at smail dot nju.edu.cn
@ 2024-04-22  9:10 ` xry111 at gcc dot gnu.org
  2024-04-22 23:33 ` [Bug tree-optimization/114800] " pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: xry111 at gcc dot gnu.org @ 2024-04-22  9:10 UTC (permalink / raw)
  To: gcc-bugs

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

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

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

--- Comment #1 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(In reply to absoler from comment #0)

> such code is compiled as: (gcc-13.2.0 -O2, regression [11/12/13/trunk])

The regression marker isn't true.  It looks like the redundant zeroing has been
there even in GCC 4.8.1.  GCC 4.7 fails to compile the test case.

And IIRC there is already an report complaining some redundant zeroing like
this...

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

* [Bug tree-optimization/114800] redundant set-zero when initiate a struct
  2024-04-22  8:27 [Bug rtl-optimization/114800] New: redundant set-zero when initiate a struct absoler at smail dot nju.edu.cn
  2024-04-22  9:10 ` [Bug rtl-optimization/114800] " xry111 at gcc dot gnu.org
@ 2024-04-22 23:33 ` pinskia at gcc dot gnu.org
  2024-04-22 23:35 ` [Bug tree-optimization/114800] DSE does not remove set-zero which is partial redundant pinskia at gcc dot gnu.org
  2024-04-22 23:40 ` [Bug tree-optimization/114800] DSE does not remove set-zero which is partial redundant with respect to mod-ref pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-22 23:33 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2024-04-22
     Ever confirmed|0                           |1
          Component|rtl-optimization            |tree-optimization

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
  tr = {};
  tr.f1 = 1;
  tr.f3 = 3;
  foo (&tr);

We are able to do DSE for tr.f0 and tr.f2 but not the original tr = {}.


Note there is some slightly difference IR from the front-ends (C does not
produce the `= {};` part while C++ does)

C++ front-end (before gimplification):
  <<cleanup_point   struct thresh_restart tr = {.f1=1, .f2=2, .f3=3};>>;
  <<cleanup_point <<< Unknown tree: expr_stmt
    tr.f0 = b >>>>>;

C front-end:
    struct thresh_restart tr = {.f0=b, .f1=1, .f2=2, .f3=3};

Note this is the DECL_EXPR here.

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

* [Bug tree-optimization/114800] DSE does not remove set-zero which is partial redundant
  2024-04-22  8:27 [Bug rtl-optimization/114800] New: redundant set-zero when initiate a struct absoler at smail dot nju.edu.cn
  2024-04-22  9:10 ` [Bug rtl-optimization/114800] " xry111 at gcc dot gnu.org
  2024-04-22 23:33 ` [Bug tree-optimization/114800] " pinskia at gcc dot gnu.org
@ 2024-04-22 23:35 ` pinskia at gcc dot gnu.org
  2024-04-22 23:40 ` [Bug tree-optimization/114800] DSE does not remove set-zero which is partial redundant with respect to mod-ref pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-22 23:35 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|redundant set-zero when     |DSE does not remove
                   |initiate a struct           |set-zero which is partial
                   |                            |redundant

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
here is a testcase which shows the problem with when either front-ends:
```
struct thresh_restart {
        int             *f0;
        int                     f1;
        int                     f2;
        int                     f3;
};

int arr[10];
void __attribute__((noinline)) foo(struct thresh_restart *p) {
    arr[0] = p->f3;
    arr[1] = p->f1;
}

void func(int *b) {
    struct thresh_restart tr = {};
    tr.f3 = 3;
    tr.f1 = 1;
    foo(&tr);
}
```

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

* [Bug tree-optimization/114800] DSE does not remove set-zero which is partial redundant with respect to mod-ref
  2024-04-22  8:27 [Bug rtl-optimization/114800] New: redundant set-zero when initiate a struct absoler at smail dot nju.edu.cn
                   ` (2 preceding siblings ...)
  2024-04-22 23:35 ` [Bug tree-optimization/114800] DSE does not remove set-zero which is partial redundant pinskia at gcc dot gnu.org
@ 2024-04-22 23:40 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-22 23:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note mod-ref does tells us that only f1, f3 are used here but DSE must have
missed that for `= {}`.

Note without the knowledge of foo, we still have a partial redundant zeroing
happening due to padding being zeroed so that might not be considered redundant
...

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

end of thread, other threads:[~2024-04-22 23:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-22  8:27 [Bug rtl-optimization/114800] New: redundant set-zero when initiate a struct absoler at smail dot nju.edu.cn
2024-04-22  9:10 ` [Bug rtl-optimization/114800] " xry111 at gcc dot gnu.org
2024-04-22 23:33 ` [Bug tree-optimization/114800] " pinskia at gcc dot gnu.org
2024-04-22 23:35 ` [Bug tree-optimization/114800] DSE does not remove set-zero which is partial redundant pinskia at gcc dot gnu.org
2024-04-22 23:40 ` [Bug tree-optimization/114800] DSE does not remove set-zero which is partial redundant with respect to mod-ref pinskia 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).