https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101401
Bug ID: 101401
Summary: strlen of a constant char vector not folded
Product: gcc
Version: 11.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
The strlen pass only folds the result in f() but not the equivalent in g(). It
should be able to handle both.
$ cat a.c && gcc -O2 -S -fdump-tree-optimized=/dev/stdout a.c
void f (void)
{
char c8[8] = { 1, 2, 3 };
if (__builtin_strlen (&c8[0]) != 3)
__builtin_abort ();
}
void g (void)
{
__attribute__ ((vector_size (8))) char c8 = { 1, 2, 3 };
if (__builtin_strlen (&c8[0]) != 3)
__builtin_abort ();
}
;; Function f (f, funcdef_no=0, decl_uid=1943, cgraph_uid=1, symbol_order=0)
void f ()
{
<bb 2> [local count: 1073741824]:
return;
}
;; Function g (g, funcdef_no=1, decl_uid=1947, cgraph_uid=2, symbol_order=1)
void g ()
{
vector(8) char c8;
long unsigned int _1;
<bb 2> [local count: 1073741824]:
c8 = { 1, 2, 3, 0, 0, 0, 0, 0 };
_1 = __builtin_strlen (&VIEW_CONVERT_EXPR<char[8]>(c8)[0]);
if (_1 != 3)
goto <bb 3>; [0.00%]
else
goto <bb 4>; [100.00%]
<bb 3> [count: 0]:
__builtin_abort ();
<bb 4> [local count: 1073741824]:
c8 ={v} {CLOBBER};
return;
}