From: Jakub Jelinek Date: Wed, 5 Dec 2001 14:17:49 +0000 (+0100) Subject: gcse.c (store_killed_in_insn): Consider pure calls as potential store killers in... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1218665b70c0577046f86c7d950832dd703a67d1;p=gcc.git gcse.c (store_killed_in_insn): Consider pure calls as potential store killers in addition to normal calls. * 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c3d9d389e92..cbd8b3ca919 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2001-12-05 Jakub Jelinek + + * gcse.c (store_killed_in_insn): Consider pure calls + as potential store killers in addition to normal calls. + 2001-12-05 Jakub Jelinek * expr.c (expand_expr): When checking promoted value, use diff --git a/gcc/gcse.c b/gcc/gcse.c index e6cc5132606..71ee0c6bead 100644 --- a/gcc/gcse.c +++ b/gcc/gcse.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5dace7b7582..95b055cb7a1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 * 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 index 00000000000..5b871bbb9ec --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/20011024-1.c @@ -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; +}