https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81741
Bug ID: 81741 Summary: Misoptimisation : replacing a constant field read access by a function call Product: gcc Version: 7.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: patrick.pelissier at gmail dot com Target Milestone: --- GCC 7.1.0 generates for the following code: #include <string.h> typedef struct string_s { unsigned long size, alloc; char *ptr; } string_t[1]; # define M_ASSUME(x) \ (! __builtin_constant_p (!!(x) || !(x)) || (x) ? \ (void) 0 : __builtin_unreachable()) int f(string_t s) { M_ASSUME(strlen(s->ptr) == s->size); return s->size; } the following code on an x86-64 platform (gcc -std=c99 -O2 -S test.c): f: subq $8, %rsp movq 16(%rdi), %rdi call strlen addq $8, %rsp ret Notice that the field access s->size is replaced by strlen(s->ptr), which is way slower. GCC 4.9 doesn't have this issue.