https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93560

            Bug ID: 93560
           Summary: strstr(s, s) not folded to s
           Product: gcc
           Version: 10.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: ---

GCC should fold strstr(a, b) to a when a and b point to the same string, the
same way Clang does.

$ cat a.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout a.c
void f (const char *s)
{
  if (__builtin_strstr (s, s) != s)   // trivially false
    __builtin_abort ();
}

;; Function f (f, funcdef_no=0, decl_uid=1930, cgraph_uid=1, symbol_order=0)

f (const char * s)
{
  char * _1;

  <bb 2> [local count: 1073741824]:
  _1 = __builtin_strstr (s_3(D), s_3(D));
  if (_1 != s_3(D))
    goto <bb 3>; [0.00%]
  else
    goto <bb 4>; [100.00%]

  <bb 3> [count: 0]:
  __builtin_abort ();

  <bb 4> [local count: 1073741824]:
  return;

}

Reply via email to