https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90663
Bug ID: 90663 Summary: [7/8/9 Regression] strcmp (&a[i], a + i) not folded for arrays and constant index Product: gcc Version: 9.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: --- The two functions below are more or less equivalent and should result in optimal code (a no-op) but starting with GCC 4.7 g() does not. Prior to GCC 4.7 both were optimized into a return statement. Clang also emits optimally efficient code here. $ cat a.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout a.c extern char a[]; void f (const char *s) { if (__builtin_strcmp (&s[2], s + 2)) // folded __builtin_abort (); } void g (void) { if (__builtin_strcmp (&a[2], a + 2)) // not folded __builtin_abort (); } ;; Function f (f, funcdef_no=0, decl_uid=1907, cgraph_uid=1, symbol_order=0) f (const char * s) { <bb 2> [local count: 1073741824]: return; } ;; Function g (g, funcdef_no=1, decl_uid=1910, cgraph_uid=2, symbol_order=1) g () { int _1; <bb 2> [local count: 1073741824]: _1 = __builtin_strcmp (&a[2], &MEM[(void *)&a + 2B]); if (_1 != 0) goto <bb 3>; [0.00%] else goto <bb 4>; [100.00%] <bb 3> [count: 0]: __builtin_abort (); <bb 4> [local count: 1073741824]: return; }