gcse.c (store_killed_in_insn): Consider pure calls as potential store killers in...
authorJakub Jelinek <jakub@redhat.com>
Wed, 5 Dec 2001 14:17:49 +0000 (15:17 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 5 Dec 2001 14:17:49 +0000 (15:17 +0100)
* gcse.c (store_killed_in_insn): Consider pure calls
as potential store killers in addition to normal calls.

* gcc.c-torture/execute/20011024-1.c: New test.

From-SVN: r47675

gcc/ChangeLog
gcc/gcse.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/20011024-1.c [new file with mode: 0644]

index c3d9d389e924213fa8f6000d9e951b5a9d460efb..cbd8b3ca91934143b315eed9c5cfe8b94f8b9f47 100644 (file)
@@ -1,3 +1,8 @@
+2001-12-05  Jakub Jelinek  <jakub@redhat.com>
+
+       * gcse.c (store_killed_in_insn): Consider pure calls
+       as potential store killers in addition to normal calls.
+
 2001-12-05  Jakub Jelinek  <jakub@redhat.com>
 
        * expr.c (expand_expr): When checking promoted value, use
index e6cc5132606b41c62cbacc6d6760aca6b8165d8e..71ee0c6bead453ef93663c5263786bc48109c072 100644 (file)
@@ -6498,8 +6498,21 @@ store_killed_in_insn (x, insn)
   
   if (GET_CODE (insn) == CALL_INSN)
     {
+      /* A normal or pure call might read from pattern,
+        but a const call will not.  */
       if (CONST_OR_PURE_CALL_P (insn))
-       return 0;
+       {
+         rtx link;
+
+         for (link = CALL_INSN_FUNCTION_USAGE (insn);
+              link;
+              link = XEXP (link, 1))
+           if (GET_CODE (XEXP (link, 0)) == USE
+               && GET_CODE (XEXP (XEXP (link, 0), 0)) == MEM
+               && GET_CODE (XEXP (XEXP (XEXP (link, 0), 0), 0)) == SCRATCH)
+             return 1;
+         return 0;
+       }
       else
        return 1;
     }
index 5dace7b75821b10081e1e222e4178c482ae9d426..95b055cb7a1304db5af0c5a3ab6f38fee3dea9c7 100644 (file)
@@ -6,6 +6,8 @@
 
        * g++.dg/other/anon-union.C: New test.
 
+       * gcc.c-torture/execute/20011024-1.c: New test.
+
 2001-12-04  Joseph S. Myers  <jsm28@cam.ac.uk>
 
        * gcc.c-torture/execute/20000722-1.x,
diff --git a/gcc/testsuite/gcc.c-torture/execute/20011024-1.c b/gcc/testsuite/gcc.c-torture/execute/20011024-1.c
new file mode 100644 (file)
index 0000000..5b871bb
--- /dev/null
@@ -0,0 +1,22 @@
+/* Test whether store motion recognizes pure functions as potentially reading
+   any memory.  */
+
+typedef __SIZE_TYPE__ size_t;
+extern void *memcpy (void *dest, const void *src, size_t n);
+extern size_t strlen (const char *s);
+extern int strcmp (const char *s1, const char *s2) __attribute__((pure));
+
+char buf[50];
+
+static void foo (void)
+{
+  if (memcpy (buf, "abc", 4) != buf) abort ();
+  if (strcmp (buf, "abc")) abort ();
+  memcpy (buf, "abcdefgh", strlen ("abcdefgh") + 1);
+}
+
+int main (void)
+{
+  foo ();
+  return 0;
+}