summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture/execute/builtins
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2004-09-15 08:19:39 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2004-09-15 08:19:39 +0000
commit9a2f233add0b478686f555ff41a47c6f6017cc69 (patch)
tree77eadc5f7abf659773934ba55f1eee0b30a67d3d /gcc/testsuite/gcc.c-torture/execute/builtins
parente599eacb132543823fec1e3690844289e9e523b0 (diff)
downloadgcc-9a2f233add0b478686f555ff41a47c6f6017cc69.tar.gz
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@87539 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.c-torture/execute/builtins')
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/memmove-2-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/memmove-2.c36
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/memmove.c14
3 files changed, 44 insertions, 7 deletions
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 ();