https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119655
Bug ID: 119655
Summary: Copy prop STRING_CST into memcpy
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: pinskia at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
void f256(char *a)
{
char t[] = "012345678901234567890123456789012345678901234567";
__builtin_memcpy(a, &t[0], sizeof(t));
}
void f256_0(char *a)
{
char t[] = "012345678901234567890123456789012345678901234567";
__builtin_memcpy(a, t, sizeof(t));
}
void f256_1(char *a)
{
const char *t = "012345678901234567890123456789012345678901234567";
__builtin_memcpy(a, &t[0], __builtin_strlen(t)+1);
}
```
These 2 should produce the same assembly code but currently does not because t
is stored to the stack and you get a stack increment.
Likewise of these:
```
void g256(char *a)
{
char t[49] = "";
__builtin_memcpy(a, &t[0], sizeof(t));
}
void g256_0(char *a)
{
char t[49] = "";
__builtin_memcpy(a, t, sizeof(t));
}
void g256_1(char *a)
{
__builtin_memset(a, 0, 49);
}
```
I have a patch which handles g256_0 (PR118947) which has been approved for GCC
16. g256/f256's memcpy is not transformed into
`MEM <unsigned char[49]> [(char * {ref-all})a_3(D)] = MEM <unsigned char[49]>
[(char * {ref-all})&t];`
Which it should be ... That would fix g256.