From: Jakub Jelinek Date: Wed, 15 Sep 2004 08:19:39 +0000 (+0200) Subject: builtins.c (expand_builtin_memmove): Optimize memmove (x, y, 1) into memcpy (x, y... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9a520f407392f0a984e7b74aa819e9f6eb3b0b90;p=gcc.git builtins.c (expand_builtin_memmove): Optimize memmove (x, y, 1) into memcpy (x, y, 1) if memcpy can be expanded inline. * builtins.c (expand_builtin_memmove): Optimize memmove (x, y, 1) into memcpy (x, y, 1) if memcpy can be expanded inline. * gcc.c-torture/execute/builtins/memmove.c (main_test): Formatting. * gcc.c-torture/execute/builtins/memmove-2.c: New test. * gcc.c-torture/execute/builtins/memmove-2-lib.c: New. From-SVN: r87539 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5432bd55a85..cfa747bbb60 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2004-09-15 Jakub Jelinek + + * builtins.c (expand_builtin_memmove): Optimize memmove (x, y, 1) + into memcpy (x, y, 1) if memcpy can be expanded inline. + 2004-09-15 Zdenek Dvorak PR tree-optimization/17468 diff --git a/gcc/builtins.c b/gcc/builtins.c index 34dceb9ef65..bf5ec081d35 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -2940,6 +2940,16 @@ expand_builtin_memmove (tree arglist, rtx target, enum machine_mode mode) target, mode, EXPAND_NORMAL); } + /* If length is 1 and we can expand memcpy call inline, + it is ok to use memcpy as well. */ + if (integer_onep (len)) + { + rtx ret = expand_builtin_mempcpy (arglist, target, mode, + /*endp=*/0); + if (ret) + return ret; + } + /* Otherwise, call the normal function. */ return 0; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3f28435ffff..8cda9ffb689 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2004-09-15 Jakub Jelinek + + * gcc.c-torture/execute/builtins/memmove.c (main_test): Formatting. + * gcc.c-torture/execute/builtins/memmove-2.c: New test. + * gcc.c-torture/execute/builtins/memmove-2-lib.c: New. + 2004-09-14 Mark Mitchell PR c++/17324 diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/memmove-2-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memmove-2-lib.c new file mode 100644 index 00000000000..5be3df52fe5 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memmove-2-lib.c @@ -0,0 +1 @@ +#include "lib/memmove.c" diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/memmove-2.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memmove-2.c new file mode 100644 index 00000000000..3afe3431338 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memmove-2.c @@ -0,0 +1,36 @@ +/* Copyright (C) 2004 Free Software Foundation. + + Check builtin memmove and bcopy optimization when length is 1. + + Written by Jakub Jelinek, 9/14/2004. */ + +extern void abort (void); +typedef __SIZE_TYPE__ size_t; +extern void *memmove (void *, const void *, size_t); +extern void bcopy (const void *, void *, size_t); +extern int memcmp (const void *, const void *, size_t); + +char p[32] = "abcdefg"; +char *q = p + 4; + +void +main_test (void) +{ + /* memmove with length 1 can be optimized into memcpy if it can be + expanded inline. */ + if (memmove (p + 2, p + 3, 1) != p + 2 || memcmp (p, "abddefg", 8)) + abort (); + if (memmove (p + 1, p + 1, 1) != p + 1 || memcmp (p, "abddefg", 8)) + abort (); + if (memmove (q, p + 4, 1) != p + 4 || memcmp (p, "abddefg", 8)) + abort (); + bcopy (p + 5, p + 6, 1); + if (memcmp (p, "abddeff", 8)) + abort (); + bcopy (p + 1, p + 1, 1); + if (memcmp (p, "abddeff", 8)) + abort (); + bcopy (q, p + 4, 1); + if (memcmp (p, "abddeff", 8)) + abort (); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/memmove.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memmove.c index 4a18fc6400f..f52332c6c13 100644 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/memmove.c +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memmove.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 Free Software Foundation. +/* Copyright (C) 2003, 2004 Free Software Foundation. Ensure builtin memmove and bcopy perform correctly. @@ -62,13 +62,13 @@ main_test (void) struct bar b1[sizeof bar/sizeof*bar]; int bz[sizeof baz/sizeof*baz]; - if (memmove (f1, foo, sizeof (foo)) != f1 || memcmp (f1, foo, sizeof(foo))) - abort(); - if (memmove (b1, bar, sizeof (bar)) != b1 || memcmp (b1, bar, sizeof(bar))) - abort(); + if (memmove (f1, foo, sizeof (foo)) != f1 || memcmp (f1, foo, sizeof (foo))) + abort (); + if (memmove (b1, bar, sizeof (bar)) != b1 || memcmp (b1, bar, sizeof (bar))) + abort (); bcopy (baz, bz, sizeof (baz)); - if (memcmp (bz, baz, sizeof(baz))) - abort(); + if (memcmp (bz, baz, sizeof (baz))) + abort (); if (memmove (p, "abcde", 6) != p || memcmp (p, "abcde", 6)) abort ();