This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Tweak string-4.c, remove string-opt-3.c (was Re: 3 GCC regressions, 1 new, with your patch on 2003-06-03T09:21:00Z.)


On Tue, Jun 03, 2003 at 01:59:37PM +0000, GCC regression checker wrote:
> With your recent patch, GCC has some regression test failures, which
> used to pass.  There are 1 new failures, and 2
> failures that existed before and after that patch; 0 failures
> have been fixed.
> 
> The new failures are:
> native gcc.sum gcc.c-torture/execute/string-opt-3.c
(and on some arches gcc.c-torture/execute/builtins/string-4.c)

There are 2 things:

One is that on certain arches like s390* STORE_BY_PIECES_P() limits heavily
how many bytes are optimized by store_by_pieces/move_by_pieces.
Before my mempcpy/stpcpy patch, if this could not be used, GCC would
"optimize" mempcpy into memcpy call followed by pointer arithmetics,
so the test passed on all arches.

Another is that for arches which don't provide mempcpy/stpcpy, I forgot to
add a simple implementation into string-opt-3.c.

The following patch allows mempcpy/stpcpy to be called in some tests
(unless on IA-32/x86-64), plus I've merged string-opt-3.c into string-4.c,
so that the implementation is there (but for string-opt-3.c tests
mempcpy/stpcpy is allowed to be called on all arches).
Tests for mempcpy/stpcpy calls where the return value is thrown away
are not allowed to call mempcpy/stpcpy at all, since that should be
unconditionally optimized into memcpy/strcpy if optimizing.

Ok to commit?

2003-06-04  Jakub Jelinek  <jakub@redhat.com>

	* gcc.c-torture/execute/builtins/string-4.c (test): New function
	with tests from string-opt-3.c.
	(main_test): Allow some mempcpy/stpcpy calls not to be optimized
	into something else.
	* gcc.c-torture/execute/string-opt-3.c: Removed.

--- gcc/testsuite/gcc.c-torture/execute/builtins/string-4.c.jj	2003-06-03 04:56:00.000000000 -0400
+++ gcc/testsuite/gcc.c-torture/execute/builtins/string-4.c	2003-06-04 06:23:10.000000000 -0400
@@ -12,18 +12,172 @@ extern size_t strlen(const char *);
 extern void *memcpy (void *, const void *, size_t);
 extern void *mempcpy (void *, const void *, size_t);
 extern int memcmp (const void *, const void *, size_t);
+extern int inside_main;
 
 const char s1[] = "123";
 char p[32] = "";
 char *s2 = "defg";
 char *s3 = "FGH";
 size_t l1 = 1;
+long buf1[64];
+char *buf2 = (char *) (buf1 + 32);
+long buf5[20];
+char buf7[20];
+
+int
+__attribute__((noinline))
+test (long *buf3, char *buf4, char *buf6, int n)
+{
+  int i = 0;
+
+  /* These should probably be handled by store_by_pieces on most arches.  */
+  if (mempcpy (buf1, "ABCDEFGHI", 9) != (char *) buf1 + 9
+      || memcmp (buf1, "ABCDEFGHI\0", 11))
+    abort ();
+
+  if (mempcpy (buf1, "abcdefghijklmnopq", 17) != (char *) buf1 + 17
+      || memcmp (buf1, "abcdefghijklmnopq\0", 19))
+    abort ();
+
+  if (__builtin_mempcpy (buf3, "ABCDEF", 6) != (char *) buf1 + 6
+      || memcmp (buf1, "ABCDEFghijklmnopq\0", 19))
+    abort ();
+
+  if (__builtin_mempcpy (buf3, "a", 1) != (char *) buf1 + 1
+      || memcmp (buf1, "aBCDEFghijklmnopq\0", 19))
+    abort ();
+
+  if (mempcpy ((char *) buf3 + 2, "bcd" + ++i, 2) != (char *) buf1 + 4
+      || memcmp (buf1, "aBcdEFghijklmnopq\0", 19)
+      || i != 1)
+    abort ();
+
+  /* These should probably be handled by move_by_pieces on most arches.  */
+  if (mempcpy ((char *) buf3 + 4, buf5, 6) != (char *) buf1 + 10
+      || memcmp (buf1, "aBcdRSTUVWklmnopq\0", 19))
+    abort ();
+
+  if (__builtin_mempcpy ((char *) buf1 + ++i + 8, (char *) buf5 + 1, 1)
+      != (char *) buf1 + 11
+      || memcmp (buf1, "aBcdRSTUVWSlmnopq\0", 19)
+      || i != 2)
+    abort ();
+
+  if (mempcpy ((char *) buf3 + 14, buf6, 2) != (char *) buf1 + 16
+      || memcmp (buf1, "aBcdRSTUVWSlmnrsq\0", 19))
+    abort ();
+
+  if (mempcpy (buf3, buf5, 8) != (char *) buf1 + 8
+      || memcmp (buf1, "RSTUVWXYVWSlmnrsq\0", 19))
+    abort ();
+
+  if (mempcpy (buf3, buf5, 17) != (char *) buf1 + 17
+      || memcmp (buf1, "RSTUVWXYZ01234567\0", 19))
+    abort ();
+
+  __builtin_memcpy (buf3, "aBcdEFghijklmnopq\0", 19);
+
+  /* These should be handled either by movstrendM or mempcpy
+     call.  */
+  if (mempcpy ((char *) buf3 + 4, buf5, n + 6) != (char *) buf1 + 10
+      || memcmp (buf1, "aBcdRSTUVWklmnopq\0", 19))
+    abort ();
+
+  if (__builtin_mempcpy ((char *) buf1 + ++i + 8, (char *) buf5 + 1, n + 1)
+      != (char *) buf1 + 12
+      || memcmp (buf1, "aBcdRSTUVWkSmnopq\0", 19)
+      || i != 3)
+    abort ();
+
+  if (mempcpy ((char *) buf3 + 14, buf6, n + 2) != (char *) buf1 + 16
+      || memcmp (buf1, "aBcdRSTUVWkSmnrsq\0", 19))
+    abort ();
+
+  i = 1;
+
+  /* These might be handled by store_by_pieces.  */
+  if (mempcpy (buf2, "ABCDEFGHI", 9) != buf2 + 9
+      || memcmp (buf2, "ABCDEFGHI\0", 11))
+    abort ();
+
+  if (mempcpy (buf2, "abcdefghijklmnopq", 17) != buf2 + 17
+      || memcmp (buf2, "abcdefghijklmnopq\0", 19))
+    abort ();
+
+  if (__builtin_mempcpy (buf4, "ABCDEF", 6) != buf2 + 6
+      || memcmp (buf2, "ABCDEFghijklmnopq\0", 19))
+    abort ();
+
+  if (__builtin_mempcpy (buf4, "a", 1) != buf2 + 1
+      || memcmp (buf2, "aBCDEFghijklmnopq\0", 19))
+    abort ();
+
+  if (mempcpy (buf4 + 2, "bcd" + i++, 2) != buf2 + 4
+      || memcmp (buf2, "aBcdEFghijklmnopq\0", 19)
+      || i != 2)
+    abort ();
+
+  /* These might be handled by move_by_pieces.  */
+  if (mempcpy (buf4 + 4, buf7, 6) != buf2 + 10
+      || memcmp (buf2, "aBcdRSTUVWklmnopq\0", 19))
+    abort ();
+
+  if (__builtin_mempcpy (buf2 + i++ + 8, buf7 + 1, 1)
+      != buf2 + 11
+      || memcmp (buf2, "aBcdRSTUVWSlmnopq\0", 19)
+      || i != 3)
+    abort ();
+
+  if (mempcpy (buf4 + 14, buf6, 2) != buf2 + 16
+      || memcmp (buf2, "aBcdRSTUVWSlmnrsq\0", 19))
+    abort ();
+
+  __builtin_memcpy (buf4, "aBcdEFghijklmnopq\0", 19);
+
+  /* These should be handled either by movstrendM or mempcpy
+     call.  */
+  if (mempcpy (buf4 + 4, buf7, n + 6) != buf2 + 10
+      || memcmp (buf2, "aBcdRSTUVWklmnopq\0", 19))
+    abort ();
+
+  if (__builtin_mempcpy (buf2 + i++ + 8, buf7 + 1, n + 1)
+      != buf2 + 12
+      || memcmp (buf2, "aBcdRSTUVWkSmnopq\0", 19)
+      || i != 4)
+    abort ();
+
+  if (mempcpy (buf4 + 14, buf6, n + 2) != buf2 + 16
+      || memcmp (buf2, "aBcdRSTUVWkSmnrsq\0", 19))
+    abort ();
+
+  /* Now stpcpy tests.  */
+  if (stpcpy ((char *) buf3, "abcdefghijklmnop") != (char *) buf1 + 16
+      || memcmp (buf1, "abcdefghijklmnop", 17))
+    abort ();
+
+  if (__builtin_stpcpy ((char *) buf3, "ABCDEFG") != (char *) buf1 + 7
+      || memcmp (buf1, "ABCDEFG\0ijklmnop", 17))
+    abort ();
+
+  if (stpcpy ((char *) buf3 + i++, "x") != (char *) buf1 + 5
+      || memcmp (buf1, "ABCDx\0G\0ijklmnop", 17))
+    abort ();
+
+  return 0;
+}
 
 void
 main_test (void)
 {
   int i;
 
+#if !defined __i386__ && !defined __x86_64__
+  /* The functions below might not be optimized into direct stores on all
+     arches.  It depends on how many instructions would be generated and
+     what limits the architecture chooses in STORE_BY_PIECES_P.  */
+  inside_main = 0;
+#endif
+
   if (stpcpy (p, "abcde") != p + 5 || memcmp (p, "abcde", 6))
     abort ();
   if (stpcpy (p + 16, "vwxyz" + 1) != p + 16 + 4 || memcmp (p + 16, "wxyz", 5))
@@ -62,8 +216,16 @@ main_test (void)
   if (__builtin_mempcpy (p, "ABCDE", 6) != p + 6 || memcmp (p, "ABCDE", 6))
     abort ();
 
+  /* These tests might call mempcpy/stpcpy on all architectures.  */
+  inside_main = 0;
+  __builtin_memcpy (buf5, "RSTUVWXYZ0123456789", 20);
+  __builtin_memcpy (buf7, "RSTUVWXYZ0123456789", 20);
+  test (buf1, buf2, "rstuvwxyz", 0);
+
   /* If the result of stpcpy/mempcpy is ignored, gcc should use
-     strcpy/memcpy.  */
+     strcpy/memcpy.  This should be optimized always, so set inside_main
+     again.  */
+  inside_main = 1;
   stpcpy (p + 3, s2);
   if (memcmp (p, "ABCdefg", 8))
     abort ();
--- gcc/testsuite/gcc.c-torture/execute/string-opt-3.c.jj	2003-06-03 04:56:00.000000000 -0400
+++ gcc/testsuite/gcc.c-torture/execute/string-opt-3.c	2003-06-04 06:26:21.000000000 -0400
@@ -1,166 +0,0 @@
-/* Copyright (C) 2003  Free Software Foundation.
-
-   Ensure that builtin mempcpy and stpcpy perform correctly.
-
-   Written by Jakub Jelinek, 21/05/2003.  */
-
-extern void abort (void);
-typedef __SIZE_TYPE__ size_t;
-extern void *mempcpy (void *, const void *, size_t);
-extern int memcmp (const void *, const void *, size_t);
-extern char *stpcpy (char *, const char *);
-
-long buf1[64];
-char *buf2 = (char *) (buf1 + 32);
-long buf5[20];
-char buf7[20];
-
-int
-__attribute__((noinline))
-test (long *buf3, char *buf4, char *buf6, int n)
-{
-  int i = 0;
-
-  /* These should probably be handled by store_by_pieces on most arches.  */
-  if (mempcpy (buf1, "ABCDEFGHI", 9) != (char *) buf1 + 9
-      || memcmp (buf1, "ABCDEFGHI\0", 11))
-    abort ();
-
-  if (mempcpy (buf1, "abcdefghijklmnopq", 17) != (char *) buf1 + 17
-      || memcmp (buf1, "abcdefghijklmnopq\0", 19))
-    abort ();
-
-  if (__builtin_mempcpy (buf3, "ABCDEF", 6) != (char *) buf1 + 6
-      || memcmp (buf1, "ABCDEFghijklmnopq\0", 19))
-    abort ();
-
-  if (__builtin_mempcpy (buf3, "a", 1) != (char *) buf1 + 1
-      || memcmp (buf1, "aBCDEFghijklmnopq\0", 19))
-    abort ();
-
-  if (mempcpy ((char *) buf3 + 2, "bcd" + ++i, 2) != (char *) buf1 + 4
-      || memcmp (buf1, "aBcdEFghijklmnopq\0", 19)
-      || i != 1)
-    abort ();
-
-  /* These should probably be handled by move_by_pieces on most arches.  */
-  if (mempcpy ((char *) buf3 + 4, buf5, 6) != (char *) buf1 + 10
-      || memcmp (buf1, "aBcdRSTUVWklmnopq\0", 19))
-    abort ();
-
-  if (__builtin_mempcpy ((char *) buf1 + ++i + 8, (char *) buf5 + 1, 1)
-      != (char *) buf1 + 11
-      || memcmp (buf1, "aBcdRSTUVWSlmnopq\0", 19)
-      || i != 2)
-    abort ();
-
-  if (mempcpy ((char *) buf3 + 14, buf6, 2) != (char *) buf1 + 16
-      || memcmp (buf1, "aBcdRSTUVWSlmnrsq\0", 19))
-    abort ();
-
-  if (mempcpy (buf3, buf5, 8) != (char *) buf1 + 8
-      || memcmp (buf1, "RSTUVWXYVWSlmnrsq\0", 19))
-    abort ();
-
-  if (mempcpy (buf3, buf5, 17) != (char *) buf1 + 17
-      || memcmp (buf1, "RSTUVWXYZ01234567\0", 19))
-    abort ();
-
-  __builtin_memcpy (buf3, "aBcdEFghijklmnopq\0", 19);
-
-  /* These should be handled either by movstrendM or mempcpy
-     call.  */
-  if (mempcpy ((char *) buf3 + 4, buf5, n + 6) != (char *) buf1 + 10
-      || memcmp (buf1, "aBcdRSTUVWklmnopq\0", 19))
-    abort ();
-
-  if (__builtin_mempcpy ((char *) buf1 + ++i + 8, (char *) buf5 + 1, n + 1)
-      != (char *) buf1 + 12
-      || memcmp (buf1, "aBcdRSTUVWkSmnopq\0", 19)
-      || i != 3)
-    abort ();
-
-  if (mempcpy ((char *) buf3 + 14, buf6, n + 2) != (char *) buf1 + 16
-      || memcmp (buf1, "aBcdRSTUVWkSmnrsq\0", 19))
-    abort ();
-
-  i = 1;
-
-  /* These might be handled by store_by_pieces.  */
-  if (mempcpy (buf2, "ABCDEFGHI", 9) != buf2 + 9
-      || memcmp (buf2, "ABCDEFGHI\0", 11))
-    abort ();
-
-  if (mempcpy (buf2, "abcdefghijklmnopq", 17) != buf2 + 17
-      || memcmp (buf2, "abcdefghijklmnopq\0", 19))
-    abort ();
-
-  if (__builtin_mempcpy (buf4, "ABCDEF", 6) != buf2 + 6
-      || memcmp (buf2, "ABCDEFghijklmnopq\0", 19))
-    abort ();
-
-  if (__builtin_mempcpy (buf4, "a", 1) != buf2 + 1
-      || memcmp (buf2, "aBCDEFghijklmnopq\0", 19))
-    abort ();
-
-  if (mempcpy (buf4 + 2, "bcd" + i++, 2) != buf2 + 4
-      || memcmp (buf2, "aBcdEFghijklmnopq\0", 19)
-      || i != 2)
-    abort ();
-
-  /* These might be handled by move_by_pieces.  */
-  if (mempcpy (buf4 + 4, buf7, 6) != buf2 + 10
-      || memcmp (buf2, "aBcdRSTUVWklmnopq\0", 19))
-    abort ();
-
-  if (__builtin_mempcpy (buf2 + i++ + 8, buf7 + 1, 1)
-      != buf2 + 11
-      || memcmp (buf2, "aBcdRSTUVWSlmnopq\0", 19)
-      || i != 3)
-    abort ();
-
-  if (mempcpy (buf4 + 14, buf6, 2) != buf2 + 16
-      || memcmp (buf2, "aBcdRSTUVWSlmnrsq\0", 19))
-    abort ();
-
-  __builtin_memcpy (buf4, "aBcdEFghijklmnopq\0", 19);
-
-  /* These should be handled either by movstrendM or mempcpy
-     call.  */
-  if (mempcpy (buf4 + 4, buf7, n + 6) != buf2 + 10
-      || memcmp (buf2, "aBcdRSTUVWklmnopq\0", 19))
-    abort ();
-
-  if (__builtin_mempcpy (buf2 + i++ + 8, buf7 + 1, n + 1)
-      != buf2 + 12
-      || memcmp (buf2, "aBcdRSTUVWkSmnopq\0", 19)
-      || i != 4)
-    abort ();
-
-  if (mempcpy (buf4 + 14, buf6, n + 2) != buf2 + 16
-      || memcmp (buf2, "aBcdRSTUVWkSmnrsq\0", 19))
-    abort ();
-
-  /* Now stpcpy tests.  */
-  if (stpcpy ((char *) buf3, "abcdefghijklmnop") != (char *) buf1 + 16
-      || memcmp (buf1, "abcdefghijklmnop", 17))
-    abort ();
-
-  if (__builtin_stpcpy ((char *) buf3, "ABCDEFG") != (char *) buf1 + 7
-      || memcmp (buf1, "ABCDEFG\0ijklmnop", 17))
-    abort ();
-
-  if (stpcpy ((char *) buf3 + i++, "x") != (char *) buf1 + 5
-      || memcmp (buf1, "ABCDx\0G\0ijklmnop", 17))
-    abort ();
-
-  return 0;
-}
-
-int
-main ()
-{
-  __builtin_memcpy (buf5, "RSTUVWXYZ0123456789", 20);
-  __builtin_memcpy (buf7, "RSTUVWXYZ0123456789", 20);
-  return test (buf1, buf2, "rstuvwxyz", 0);
-}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]