public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Disallow TER of pure/const/noreturn calls (PR tree-optimization/33619)
@ 2007-10-11 21:47 Jakub Jelinek
  2007-10-12 17:55 ` Diego Novillo
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2007-10-11 21:47 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andrew MacLeod, Diego Novillo

Hi!

As discussed in the bugzilla, for GCC 4.2+ I don't see what does TER
of calls buy us, except bugs it introduces when code over which a pure or
const call is moved is using DECL_HARD_REGISTER.
For GCC 4.1 perhaps instead of returning false for all calls it should
return true for __builtin_expect.

Regtested on x86_64-linux, ok for trunk?

2007-10-11  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/33619
	* tree-ssa-ter.c (is_replaceable_p): Return false for all
	calls.

	* gcc.dg/pr33619.c: New test.

--- gcc/tree-ssa-ter.c.jj	2007-10-02 14:51:12.000000000 +0200
+++ gcc/tree-ssa-ter.c	2007-10-11 22:09:56.000000000 +0200
@@ -402,14 +402,9 @@ is_replaceable_p (tree stmt)
       && DECL_HARD_REGISTER (GENERIC_TREE_OPERAND (stmt, 1)))
     return false;
 
-  /* Calls to functions with side-effects cannot be replaced.  */
+  /* No function calls can be replaced.  */
   if ((call_expr = get_call_expr_in (stmt)) != NULL_TREE)
-    {
-      int call_flags = call_expr_flags (call_expr);
-      if (TREE_SIDE_EFFECTS (call_expr)
-	  && !(call_flags & (ECF_PURE | ECF_CONST | ECF_NORETURN)))
-	return false;
-    }
+    return false;
 
   /* Leave any stmt with volatile operands alone as well.  */
   if (stmt_ann (stmt)->has_volatile_ops)
--- gcc/testsuite/gcc.dg/pr33619.c.jj	2007-10-11 22:13:04.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr33619.c	2007-10-11 23:40:47.000000000 +0200
@@ -0,0 +1,45 @@
+/* PR tree-optimization/33619 */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#ifdef __powerpc__
+# define REG1 __asm__ ("3")
+# define REG2 __asm__ ("4")
+#elif defined __x86_64__
+# define REG1 __asm__ ("rdi")
+# define REG2 __asm__ ("rsi")
+#else
+# define REG1
+# define REG2
+#endif
+
+static inline void
+bar (unsigned long x, int y)
+{
+  register unsigned long p1 REG1 = x;
+  register unsigned long p2 REG2 = y;
+  __asm__ volatile ("" : "=r" (p1), "=r" (p2) : "0" (p1), "1" (p2) : "memory");
+  if (p1 != 0xdeadUL || p2 != 0xbefUL)
+    __builtin_abort ();
+}
+
+__attribute__((const, noinline)) int
+baz (int x)
+{
+  return x;
+}
+
+__attribute__((noinline)) void
+foo (unsigned long *x, int y)
+{
+  unsigned long a = *x;
+  bar (a, baz (y));
+}
+
+int
+main (void)
+{
+  unsigned long a = 0xdeadUL;
+  foo (&a, 0xbefUL);
+  return 0;
+}

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Disallow TER of pure/const/noreturn calls (PR tree-optimization/33619)
  2007-10-11 21:47 [PATCH] Disallow TER of pure/const/noreturn calls (PR tree-optimization/33619) Jakub Jelinek
@ 2007-10-12 17:55 ` Diego Novillo
  0 siblings, 0 replies; 2+ messages in thread
From: Diego Novillo @ 2007-10-12 17:55 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Andrew MacLeod

On 10/11/07, Jakub Jelinek <jakub@redhat.com> wrote:

>         PR tree-optimization/33619
>         * tree-ssa-ter.c (is_replaceable_p): Return false for all
>         calls.
>
>         * gcc.dg/pr33619.c: New test.

OK.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-10-12 17:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-11 21:47 [PATCH] Disallow TER of pure/const/noreturn calls (PR tree-optimization/33619) Jakub Jelinek
2007-10-12 17:55 ` Diego Novillo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).