re PR tree-optimization/54200 (copyrename generates wrong debuginfo)
authorRichard Guenther <rguenther@suse.de>
Mon, 13 Aug 2012 09:29:28 +0000 (09:29 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 13 Aug 2012 09:29:28 +0000 (09:29 +0000)
2012-08-13  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/54200
* tree-ssa-copyrename.c (rename_ssa_copies): Do not add
PHI results to another partition if not all PHI arguments
have the same partition.

* gcc.dg/guality/pr54200.c: New testcase.
* gcc.dg/tree-ssa/slsr-8.c: Adjust.

From-SVN: r190339

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/guality/pr54200.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/slsr-8.c
gcc/tree-ssa-copyrename.c

index 0108a0d..acdfadb 100644 (file)
@@ -1,3 +1,10 @@
+2012-08-13  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/54200
+       * tree-ssa-copyrename.c (rename_ssa_copies): Do not add
+       PHI results to another partition if not all PHI arguments
+       have the same partition.
+
 2012-08-12  Jan Hubicka  <jh@suse.cz>
 
        * tree-pass.h (write_summary, write_optimization_summary): Remove
index a9df8b7..f09347a 100644 (file)
@@ -1,3 +1,9 @@
+2012-08-13  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/54200
+       * gcc.dg/guality/pr54200.c: New testcase.
+       * gcc.dg/tree-ssa/slsr-8.c: Adjust.
+
 2012-08-12  Oleg Endo  <olegendo@gcc.gnu.org>
 
        * gcc.target/sh/prefetch.c: Add -m3* to inclusion list.
diff --git a/gcc/testsuite/gcc.dg/guality/pr54200.c b/gcc/testsuite/gcc.dg/guality/pr54200.c
new file mode 100644 (file)
index 0000000..9b17187
--- /dev/null
@@ -0,0 +1,28 @@
+/* PR tree-optimization/54200 */
+/* { dg-do run } */
+/* { dg-options "-g -fno-var-tracking-assignments" } */
+
+int o __attribute__((used));
+
+void bar (void) { o = 2; }
+
+int __attribute__((noinline,noclone))
+foo (int z, int x, int b)
+{
+  if (x == 1)
+    {
+      bar ();
+      return z;
+    }
+  else
+    {
+      int a = (x + z) + b;
+      return a; /* { dg-final { gdb-test 20 "z" "3" } } */
+    }
+}
+
+int main ()
+{
+  foo (3, 2, 1);
+  return 0;
+}
index b03c52c..c2e9b61 100644 (file)
@@ -17,7 +17,7 @@ f (int s, int *c)
   return x1 ? x2 : x3;
 }
 
-/* There are 2 ' * ' instances in the decls (since "int * x3;" is
-   optimized out), 1 parm, 2 in the code.  */
-/* { dg-final { scan-tree-dump-times " \\* " 5 "optimized" } } */
+/* There are 4 ' * ' instances in the decls (since "int * iftmp.0;" is
+   added), 1 parm, 2 in the code.  */
+/* { dg-final { scan-tree-dump-times " \\* " 7 "optimized" } } */
 /* { dg-final { cleanup-tree-dump "optimized" } } */
index 82f8c64..387e67b 100644 (file)
@@ -348,15 +348,53 @@ rename_ssa_copies (void)
          res = gimple_phi_result (phi);
 
          /* Do not process virtual SSA_NAMES.  */
-         if (!is_gimple_reg (res))
+         if (virtual_operand_p (res))
            continue;
 
-          for (i = 0; i < gimple_phi_num_args (phi); i++)
-            {
-              tree arg = gimple_phi_arg (phi, i)->def;
-              if (TREE_CODE (arg) == SSA_NAME)
-               updated |= copy_rename_partition_coalesce (map, res, arg, debug);
-            }
+         /* Make sure to only use the same partition for an argument
+            as the result but never the other way around.  */
+         if (SSA_NAME_VAR (res)
+             && !DECL_IGNORED_P (SSA_NAME_VAR (res)))
+           for (i = 0; i < gimple_phi_num_args (phi); i++)
+             {
+               tree arg = PHI_ARG_DEF (phi, i);
+               if (TREE_CODE (arg) == SSA_NAME)
+                 updated |= copy_rename_partition_coalesce (map, res, arg,
+                                                            debug);
+             }
+         /* Else if all arguments are in the same partition try to merge
+            it with the result.  */
+         else
+           {
+             int all_p_same = -1;
+             int p = -1;
+             for (i = 0; i < gimple_phi_num_args (phi); i++)
+               {
+                 tree arg = PHI_ARG_DEF (phi, i);
+                 if (TREE_CODE (arg) != SSA_NAME)
+                   {
+                     all_p_same = 0;
+                     break;
+                   }
+                 else if (all_p_same == -1)
+                   {
+                     p = partition_find (map->var_partition,
+                                         SSA_NAME_VERSION (arg));
+                     all_p_same = 1;
+                   }
+                 else if (all_p_same == 1
+                          && p != partition_find (map->var_partition,
+                                                  SSA_NAME_VERSION (arg)))
+                   {
+                     all_p_same = 0;
+                     break;
+                   }
+               }
+             if (all_p_same == 1)
+               updated |= copy_rename_partition_coalesce (map, res,
+                                                          PHI_ARG_DEF (phi, 0),
+                                                          debug);
+           }
         }
     }