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] Don't assume const/pure calls are total (fix PR tree-optimization/19828)


Hi!

As per discussion in PR tree-optimization/19828, we should not assume
const/pure calls are total and therefore can't hoist them out of loops
unless we know they will be executed (at least once).

Perhaps LIM could see if they are guarded just by some loop invariant
and in that case hoist it before the loop guarded with that invariant.

Ok to commit?

2005-02-18  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/19828
	* tree-ssa-loop-im.c (movement_possibility): Return
	MOVE_PRESERVE_EXECUTION for calls without side-effects.

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

--- gcc/tree-ssa-loop-im.c.jj	2005-01-22 08:49:01.000000000 +0100
+++ gcc/tree-ssa-loop-im.c	2005-02-18 17:21:28.794793302 +0100
@@ -224,7 +224,8 @@ movement_possibility (tree stmt)
     return MOVE_IMPOSSIBLE;
 
   if (TREE_CODE (lhs) != SSA_NAME
-      || tree_could_trap_p (rhs))
+      || tree_could_trap_p (rhs)
+      || get_call_expr_in (stmt))
     return MOVE_PRESERVE_EXECUTION;
 
   return MOVE_POSSIBLE;
--- gcc/testsuite/gcc.c-torture/execute/20050218-1.c.jj	2005-01-27 14:27:08.338732320 +0100
+++ gcc/testsuite/gcc.c-torture/execute/20050218-1.c	2005-02-18 17:24:35.316666039 +0100
@@ -0,0 +1,30 @@
+/* PR tree-optimization/19828 */
+typedef __SIZE_TYPE__ size_t;
+extern size_t strlen (const char *s);
+extern int strncmp (const char *s1, const char *s2, size_t n);
+extern void abort (void);
+
+const char *a[16] = { "a", "bc", "de", "fgh" };
+
+int
+foo (char *x, const char *y, size_t n)
+{
+  size_t i, j = 0;
+  for (i = 0; i < n; i++)
+    {
+      if (strncmp (x + j, a[i], strlen (a[i])) != 0)
+        return 2;
+      j += strlen (a[i]);
+      if (y)
+        j += strlen (y);
+    }
+  return 0;
+}
+
+int
+main (void)
+{
+  if (foo ("abcde", (const char *) 0, 3) != 0)
+    abort ();
+  return 0;
+}

	Jakub


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