re PR tree-optimization/46398 (early FRE miscompiles simple testcase)
authorRichard Biener <rguenth@gcc.gnu.org>
Wed, 10 Nov 2010 10:59:20 +0000 (10:59 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 10 Nov 2010 10:59:20 +0000 (10:59 +0000)
2010-11-10  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/46398
* tree-ssa-sccvn.c (process_scc): Iterate for all PHIs.

* gcc.dg/torture/pr46398.c: New testcase.

From-SVN: r166527

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr46398.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.c

index 939e03ad50024393edb03870a86b7069c2d7f08d..ff1ef623e9d84a5ac7cd588fef5a55c71353fe57 100644 (file)
@@ -1,3 +1,8 @@
+2010-11-10  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/46398
+       * tree-ssa-sccvn.c (process_scc): Iterate for all PHIs.
+
 2010-11-10  Joern Rennecke  <amylaar@spamcop.net>
 
        PR target/44760
index 52e7693e4476f8d4fb22d007a219501139e375a1..e4ae2acf84982f89b214cc1c0e1f532248111ca9 100644 (file)
@@ -1,10 +1,16 @@
+2010-11-10  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/46398
+       * gcc.dg/torture/pr46398.c: New testcase.
+
 2010-11-09  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        * gfortran.dg/open_dev_null.f90: New test.
 
 2010-11-09   Jan Hubicka  <jh@suse.cz>
 
-       * testsuite/gcc.target/i386/recip-vec-sqrtf-avx.c: Update for loop unrolling.
+       * testsuite/gcc.target/i386/recip-vec-sqrtf-avx.c: Update for loop
+       unrolling.
 
 2010-11-09  Joseph Myers  <joseph@codesourcery.com>
 
diff --git a/gcc/testsuite/gcc.dg/torture/pr46398.c b/gcc/testsuite/gcc.dg/torture/pr46398.c
new file mode 100644 (file)
index 0000000..9110bbb
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-do run } */
+
+int __attribute__((noinline))
+test (int token)
+{
+  int done = 0;
+  int virtual_p = 0;
+  while (!done)
+    {
+      if (token == 42)
+       virtual_p = 1;
+      else
+       done = 1;
+    }
+  return virtual_p;
+}
+extern void abort (void);
+int
+main()
+{
+  if (test (0) != 0)
+    abort ();
+  return 0;
+}
index 02613aabda190af315d28ce2f33bfec002652a24..994e94596cbc13a5b85e440921ea69775a6d1db9 100644 (file)
@@ -3108,9 +3108,20 @@ process_scc (VEC (tree, heap) *scc)
   if (VEC_length (tree, scc) == 1)
     {
       tree use = VEC_index (tree, scc, 0);
-      if (!VN_INFO (use)->use_processed)
-       visit_use (use);
-      return;
+      if (VN_INFO (use)->use_processed)
+       return;
+      /* We need to make sure it doesn't form a cycle itself, which can
+        happen for self-referential PHI nodes.  In that case we would
+        end up inserting an expression with VN_TOP operands into the
+        valid table which makes us derive bogus equivalences later.
+        The cheapest way to check this is to assume it for all PHI nodes.  */
+      if (gimple_code (SSA_NAME_DEF_STMT (use)) == GIMPLE_PHI)
+       /* Fallthru to iteration.  */ ;
+      else
+       {
+         visit_use (use);
+         return;
+       }
     }
 
   /* Iterate over the SCC with the optimistic table until it stops