Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tree-ssa-strlen] possible strlen optimization for memcmp/strcmp of arrays #14

Open
xiangzhai opened this issue Jan 23, 2018 · 0 comments
Labels
Milestone

Comments

@xiangzhai
Copy link

Hi fellows,

As PR82950 mentioned:
Testcase:

$ cat c.c
char a[4];
char b[4];

int f (void)
{
  __builtin_strcpy (a, "abc");
  __builtin_strcpy (b, "abc");
  return __builtin_strcmp (a, b);   // not folded but could be
}

int g (const char *s)
{
  __builtin_strcpy (a, s);
  __builtin_strcpy (b, s);
  return __builtin_strcmp (a, b);   // not folded but could be
}

GCC 5.5 and 8x. failed to folded:

$ /opt/loongson-gnu-5.5/bin/mips64-linux-gnu-gcc -O2 -S -Wall -Wextra -Wpedantic -fdump-tree-optimized=/dev/stdout t.c

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

f (char * d)
{
  void * _4;
  long unsigned int _6;
  unsigned int _7;

  <bb 2>:
  __builtin_memcpy (d_2(D), "abc", 3);
  _4 = d_2(D) + 3;
  __builtin_memcpy (_4, "def", 4);
  _6 = __builtin_strlen (d_2(D));
  _7 = (unsigned int) _6;
  return _7;

}



;; Function g (g, funcdef_no=1, decl_uid=1489, cgraph_uid=1, symbol_order=1)

g (char * d)
{
  void * _4;
  long unsigned int _6;
  unsigned int _7;

  <bb 2>:
  _4 = __builtin_mempcpy (d_2(D), "abc", 3);
  __builtin_mempcpy (_4, "def", 4);
  _6 = __builtin_strlen (d_2(D));
  _7 = (unsigned int) _6;
  return _7;

}

Regards,
Leslie Zhai

@xiangzhai xiangzhai added the bug label Jan 23, 2018
@xiangzhai xiangzhai added this to the gcc-8-branch milestone Feb 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant