PR tree-optimization/81303
[official-gcc.git] / gcc / testsuite / gcc.dg / string-opt-1.c
blob2f060732bf042e7083dfef0824ffc3c84b6e65a4
1 /* Ensure mempcpy is "optimized" into memcpy followed by addition. */
2 /* { dg-do compile } */
3 /* { dg-options "-O2" } */
5 char *buffer;
6 char *test;
8 #define SIZE 100
10 char *
11 __attribute__((noinline))
12 my_memcpy (char *d, char *s, unsigned l)
14 return __builtin_memcpy (d, s, l);
17 char *
18 __attribute__((noinline))
19 my_mempcpy (char *d, char *s, unsigned l)
21 return __builtin_mempcpy (d, s, l);
24 void
25 run_test (char *d, char *s, unsigned l)
27 char *r = my_mempcpy (d, s, l);
28 if (r != d + l)
29 __builtin_abort ();
31 r = my_memcpy (d, s, l);
32 if (r != d)
33 __builtin_abort ();
36 int
37 main (void)
39 const char* const foo = "hello world";
40 unsigned l = __builtin_strlen (foo) + 1;
42 buffer = __builtin_malloc (SIZE);
43 __builtin_memcpy (buffer, foo, l);
44 test = __builtin_malloc (SIZE);
46 run_test (test, buffer, l);
48 return 0;
51 /* { dg-final { scan-assembler-not "\<mempcpy\>" } } */
52 /* { dg-final { scan-assembler "memcpy" } } */