https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62156
Bug ID: 62156 Summary: memcmp doesn't see through memcpy at compile-time Product: gcc Version: 5.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: glisse at gcc dot gnu.org int f(){ const char*a="abcdefghijkl"; const char*b="acbdefghijkl"; char*c=(char*)__builtin_malloc(42); __builtin_memcpy(c,b,13); return __builtin_memcmp(a,c,5); } We have no problem computing strlen(c) or memcmp(a,b,5) at compile-time, but we don't manage to fold this. This type of code is what we get with std::string when we inline everything.