[Bug tree-optimization/82571] missing strlen optimization for memchr

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri May 11 15:20:00 GMT 2018


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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |6.4.0, 7.3.0, 8.1.0

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Looks like I forgot to include a test case in comment #0.  Here's a simple one
showing the optimization done for strchr and the missing equivalent
optimization for memchr.

$ cat t.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout t.c
int f0 (void)
{
  char a[] = "123";
  return 0 != __builtin_strchr (a, 0);   // folded to 1
}

int f1 (void)
{
  char a[] = "123";
  return 0 != __builtin_memchr (a, 0, sizeof a);   // not folded but could be
}

;; Function f0 (f0, funcdef_no=0, decl_uid=1956, cgraph_uid=0, symbol_order=0)

f0 ()
{
  <bb 2> [local count: 1073741825]:
  return 1;

}



;; Function f1 (f1, funcdef_no=1, decl_uid=1960, cgraph_uid=1, symbol_order=1)

f1 ()
{
  char a[4];
  void * _1;
  _Bool _2;
  int _5;

  <bb 2> [local count: 1073741825]:
  a = "123";
  _1 = __builtin_memchr (&a, 0, 4);
  _2 = _1 != 0B;
  _5 = (int) _2;
  a ={v} {CLOBBER};
  return _5;

}


More information about the Gcc-bugs mailing list