Bug 112272 - suboptimal zero-initialization of struct of mixed pointer and integer types
Summary: suboptimal zero-initialization of struct of mixed pointer and integer types
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 14.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks: vectorizer
  Show dependency treegraph
 
Reported: 2023-10-29 08:13 UTC by LIU Hao
Modified: 2023-11-04 05:57 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-pc-linux
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-11-04 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description LIU Hao 2023-10-29 08:13:19 UTC
Testcase:
(https://gcc.godbolt.org/z/97cThnszM)

```
struct data_mixed
  {
    int* p1;
    int* p2;
    __INTPTR_TYPE__ i3;
    int* p4;

    constexpr data_mixed() noexcept : p1(), p2(), i3(), p4() { }
  };

data_mixed
create_data_mixed()
  {
    return {};  // somehow suboptimal ↓↓
//        mov     QWORD PTR [rdi+16], 0
//        mov     QWORD PTR [rdi+24], 0
//        vmovdqu XMMWORD PTR [rdi], xmm0
  }


struct data_ptrs
  {
    int* p1;
    int* p2;
    void* p3;
    int* p4;

    constexpr data_ptrs() noexcept : p1(), p2(), p3(), p4() { }
  };

data_ptrs
create_data_ptrs()
  {
    return {};     // vmovdqu YMMWORD PTR [rdi], ymm0
  }


struct data_ints
  {
    __INTPTR_TYPE__ p1;
    __INTPTR_TYPE__ p2;
    __INTPTR_TYPE__ p3;
    __INTPTR_TYPE__ p4;

    constexpr data_ints() noexcept : p1(), p2(), p3(), p4() { }
  };

data_ints
create_data_ints()
  {
    return {};      // vmovdqu YMMWORD PTR [rdi], ymm0
  }
```

I believe these structs should be initialized in the same way, by storing a zero YMM register. However mixed use of pointer and integer types seems to prevent that. This is not specific to GCC 13; in GCC 12 it used to prevent vectorization completely.
Comment 1 Andrew Pinski 2023-11-04 05:57:37 UTC
Confirmed.

I don't know why the SLP vectorizer rejects it.

Though I wonder why store merging also rejects it for a cost reason ...