https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102382
Bug ID: 102382 Summary: Missing optimization for strlen after enable O2 vectorization Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: crazylht at gmail dot com Target Milestone: --- testcase is from strlenopt-85.c void* elim_strlen_calloc_store_memset_1 (unsigned a, unsigned b) { char *p = __builtin_calloc (a, 1); p[0] = '\0'; p[1] = '\0'; p[2] = '\0'; p[3] = '\0'; __builtin_memset (p, 0, b); n0 = __builtin_strlen (p); return p; } diff --git a/strlenopt-85.c.193t.strlen1 b/../vectorize/strlenopt-85.c.193t.strlen1 index 2c8bc4a..6591d9e 100644 --- a/strlenopt-85.c.193t.strlen1 +++ b/../vectorize/strlenopt-85.c.193t.strlen1 @@ -10,6 +10,8 @@ ;; 2 succs { 1 } void * elim_strlen_calloc_store_memset_1 (unsigned int a, unsigned int b) { + vector(4) char * vectp.5; + vector(4) char * vectp_p.4; char * p; long unsigned int _1; long unsigned int _2; @@ -19,11 +21,10 @@ void * elim_strlen_calloc_store_memset_1 (unsigned int a, unsigned int b) <bb 2> [local count: 1073741824]: _1 = (long unsigned int) a_5(D); p_8 = __builtin_calloc (_1, 1); - MEM[(char *)p_8 + 1B] = 0; - MEM[(char *)p_8 + 2B] = 0; - MEM[(char *)p_8 + 3B] = 0; + MEM <vector(4) char> [(char *)p_8] = { 0, 0, 0, 0 }; _2 = (long unsigned int) b_13(D); - _3 = 0; + __builtin_memset (p_8, 0, _2); + _3 = __builtin_strlen (p_8); _4 = (unsigned int) _3; n0 = _4; return p_8; It seems to be a missing optimization here.