[Bug middle-end/114342] suboptimal codegen of vector::vector(range)

2024-03-19 Thread hiraditya at msn dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114342

AK  changed:

   What|Removed |Added

 Resolution|--- |DUPLICATE
Version|unknown |14.0
 Status|NEW |RESOLVED

--- Comment #3 from AK  ---
I see. marking as duplicate. Thanks for clarifying!

*** This bug has been marked as a duplicate of bug 59863 ***

[Bug middle-end/114342] suboptimal codegen of vector::vector(range)

2024-03-14 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114342

Andrew Pinski  changed:

   What|Removed |Added

 Ever confirmed|0   |1
 Status|UNCONFIRMED |NEW
   Severity|normal  |enhancement
   Last reconfirmed||2024-03-14

--- Comment #2 from Andrew Pinski  ---
If you change `arr` to be: `static const int arr[]`. then GCC can do it with
only one memcpy.

So basically GCC does not know it remove arr from being a stack variable.

clang/LLVM is able to figure that out but it definitely requires inlining to do
that.

```
  arr = *.LC0;
...
  __builtin_memcpy (_21, , 444);
```

Basically GCC does not realize it can "remove" the local variable arr here.

Note there are duplicates of this bug report already too.

[Bug middle-end/114342] suboptimal codegen of vector::vector(range)

2024-03-14 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114342

--- Comment #1 from Andrew Pinski  ---
The first memcpy (rep movsq) is for:
```
  int arr[]{-5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10,
15, -5, 10, 15,-5, 10, 15 -5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5,
10, 15, -5, 10, 15, -5, 10,-5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5,
10, 15, -5, 10,-5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5,
10,-5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10,-5, 10,
15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10, 15, -5, 10,};

```


The second memcpy is copying arr into the vector.
```
  _25 = operator new (444);

   [local count: 1073741824]:
  dd_2(D)->D.81462._M_impl.D.80768._M_start = _25;
  _16 = _25 + 444;
  dd_2(D)->D.81462._M_impl.D.80768._M_end_of_storage = _16;
  __builtin_memcpy (_25, , 444);
```