https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115423
Bug ID: 115423 Summary: Inlined strcmp optimizes poorly Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: blubban at gmail dot com Target Milestone: --- bool g(const char* c) { return __builtin_strcmp(c, ".") == 0 || __builtin_strcmp(c, "..") == 0; } bool h(const char* c) { return (c[0] == '.' && c[1] == '\0') || (c[0] == '.' && c[1] == '.' && c[2] == '\0'); } Compile with -O2. Expected result: Same output from both. Actual: The former results in a mess that, among other inefficiencies, loads c[0] twice. Online reproducer: https://godbolt.org/z/E4vEshvcM (I don't know if this is an RTL or tree optimizer issue, I just guessed. Feel free to move it if it's wrong.)