https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122754
Bug ID: 122754
Summary: strlen missed opt with vectorization turned on
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Blocks: 83819
Target Milestone: ---
Take the C++ code:
```
struct f
{
char s[2];
};
f s;
int f(void)
{
#if 1
char &t = s.s[0];
char &t1 = s.s[1];
t = 0;
t1 = 0;
#else
char *t = &s.s[0];
char *t1 = &s.s[1];
*t = 0;
*t1 = 0;
#endif
int t0 = __builtin_strlen(s.s);
return t0;
}
```
This should be optimized to `return 0;` but currently we don't. the strlen code
does not like:
MEM <vector(2) char> [(char &)&s] = { 0, 0 };
_1 = __builtin_strlen (&s.s);
If we switch over to using pointers instead of reference, it works and the IR
at this point is:
MEM <vector(2) char> [(char *)&s] = { 0, 0 };
_1 = __builtin_strlen (&s.s);
>From me 100000x view from the outside seems like it is a pointer vs reference
issue.
This is reduced from the testcase in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86701#c5 .
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83819
[Bug 83819] [meta-bug] missing strlen optimizations