https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86042
Bug ID: 86042 Summary: [8 Regression] missing strlen optimization after second strcpy Product: gcc Version: 8.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: --- GCC 7 and prior eliminate both strlen() calls in the program below. GCC 8 only eliminates the first call, emitting worse code than prior versions. $ cat c.c && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout c.c char a[3]; int main () { int n[2]; __builtin_strcpy (a, "12"); n[0] = __builtin_strlen (a); __builtin_strcpy (a, "12"); n[1] = __builtin_strlen (a); __builtin_printf ("%i %i\n", n[0], n[1]); } ;; Function main (main, funcdef_no=0, decl_uid=1956, cgraph_uid=0, symbol_order=1) (executed once) main () { long unsigned int _3; int _4; <bb 2> [local count: 1073741825]: MEM[(char * {ref-all})&a] = MEM[(char * {ref-all})"12"]; _3 = __builtin_strlen (&a); _4 = (int) _3; __builtin_printf ("%i %i\n", 2, _4); return 0; }