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
This commit is contained in:
parent
b1d16eff57
commit
9a520f4073
|
@ -1,3 +1,8 @@
|
|||
2004-09-15 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
* 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 <rakdver@atrey.karlin.mff.cuni.cz>
|
||||
|
||||
PR tree-optimization/17468
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
2004-09-15 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
* 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 <mark@codesourcery.com>
|
||||
|
||||
PR c++/17324
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
#include "lib/memmove.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 ();
|
||||
}
|
|
@ -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 ();
|
||||
|
|
Loading…
Reference in New Issue