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
```

Reply via email to