view gcc/testsuite/gcc.dg/fold-bcopy.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
line wrap: on
line source

/* PR tree-optimization/80933 - redundant bzero/bcopy calls not eliminated
   { dg-do compile }
   { dg-options "-O0 -Wall -fdump-tree-gimple" } */

void f0 (void *dst, const void *src, unsigned n)
{
  /* Bcopy(src, dst, ...) corresponds to memmove(dst, src, ...),
     with the first two arguments transposed, not memcpy.  */
  __builtin_bcopy (src, dst, n);
}

void f1 (void *p, const void *q, unsigned n)
{
  /* A call with zero size should be eliminated.  */
  __builtin_bcopy (q, p, 0);
}

int f2 (const void *p, const void *q, unsigned n)
{
  return __builtin_bcmp (p, q, n);
}

int f3 (const void *p, const void *q)
{
  /* A call with zero size should be folded into 0.  */
  return __builtin_bcmp (p, q, 0);
}

int f4 (const void *p, unsigned n)
{
  /* A call with the same argument should also be folded into 0.  */
  return __builtin_bcmp (p, p, n);
}

void f5 (void *p, unsigned n)
{
  __builtin_bzero (p, n);
}

void f6 (void *p)
{
  /* A call with zero size should be eliminated.  */
  __builtin_bzero (p, 0);
}

/* Verify that calls to bcmp, bcopy, and bzero have all been removed
   and one of each replaced with memcmp, memmove, and memset, respectively.
   The remaining three should be eliminated.
  { dg-final { scan-tree-dump-not "bcmp|bcopy|bzero" "gimple" } }
  { dg-final { scan-tree-dump-times "memcmp|memmove|memset" 3 "gimple" } }

  Verify that the bcopy to memmove transformation correctly transposed
  the source and destination pointer arguments.
  { dg-final { scan-tree-dump-times "memmove \\(dst, src" 1 "gimple" } }  */