https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79547
Bug ID: 79547 Summary: duplicate strlen calls with same argument not folded Product: gcc Version: 7.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: --- As mentioned in bug 71315 comment 3, GCC folds the first of a series of calls to strlen with the same argument but not the subsequent ones: $ cat t.c && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout t.c void f (unsigned); void f1 (void) { char s[] = "1234"; f (__builtin_strlen (s)); } void f2 (void) { char s[] = "1234"; f (__builtin_strlen (s)); f (__builtin_strlen (s)); } void f3 (void) { char s[] = "1234"; f (__builtin_strlen (s)); f (__builtin_strlen (s)); f (__builtin_strlen (s)); } ;; Function f1 (f1, funcdef_no=0, decl_uid=1797, cgraph_uid=0, symbol_order=0) f1 () { char s[5]; <bb 2> [100.00%]: s = "1234"; f (4); s ={v} {CLOBBER}; return; } ;; Function f2 (f2, funcdef_no=1, decl_uid=1801, cgraph_uid=1, symbol_order=1) f2 () { char s[5]; long unsigned int _3; unsigned int _4; <bb 2> [100.00%]: s = "1234"; f (4); _3 = __builtin_strlen (&s); _4 = (unsigned int) _3; f (_4); s ={v} {CLOBBER}; return; } ;; Function f3 (f3, funcdef_no=2, decl_uid=1805, cgraph_uid=2, symbol_order=2) f3 () { char s[5]; long unsigned int _3; unsigned int _4; long unsigned int _5; unsigned int _6; <bb 2> [100.00%]: s = "1234"; f (4); _3 = __builtin_strlen (&s); _4 = (unsigned int) _3; f (_4); _5 = __builtin_strlen (&s); _6 = (unsigned int) _5; f (_6); s ={v} {CLOBBER}; return; }