2012-12-19 Richard Biener <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 19 Dec 2012 13:53:18 +0000 (13:53 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 19 Dec 2012 13:53:18 +0000 (13:53 +0000)
PR tree-optimization/55736
PR tree-optimization/55703
* gimplify.c (prune_expr_location): New function.
(unshare_expr_without_location): Likewise.
* tree.h (unshare_expr_without_location): Declare.
* ipa-prop.c (prune_expression_for_jf): Remove.
(prune_expression_for_jf_1): Likewise.
(ipa_set_jf_constant): Use unshare_expr_without_location.
(ipa_set_jf_arith_pass_through): Likewise.
(determine_known_aggregate_parts): Likewise.
* tree-switch-conversion.c (build_constructors): Use
unshare_expr_without_location on all constructor elements.

* gcc.dg/lto/pr55703_0.c: New testcase.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@194609 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/gimplify.c
gcc/ipa-prop.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/lto/pr55703_0.c [new file with mode: 0644]
gcc/tree-switch-conversion.c
gcc/tree.h

index fe52e01..c7f3643 100644 (file)
@@ -1,3 +1,18 @@
+2012-12-19  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/55736
+       PR tree-optimization/55703
+       * gimplify.c (prune_expr_location): New function.
+       (unshare_expr_without_location): Likewise.
+       * tree.h (unshare_expr_without_location): Declare.
+       * ipa-prop.c (prune_expression_for_jf): Remove.
+       (prune_expression_for_jf_1): Likewise.
+       (ipa_set_jf_constant): Use unshare_expr_without_location.
+       (ipa_set_jf_arith_pass_through): Likewise.
+       (determine_known_aggregate_parts): Likewise.
+       * tree-switch-conversion.c (build_constructors): Use
+       unshare_expr_without_location on all constructor elements.
+
 2012-12-19  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>
 
        * target.def: Define canonicalize_comparison hook.
index 384adb2..f628b8a 100644 (file)
@@ -1059,6 +1059,30 @@ unshare_expr (tree expr)
   walk_tree (&expr, mostly_copy_tree_r, NULL, NULL);
   return expr;
 }
+
+/* Worker for unshare_expr_without_location.  */
+
+static tree
+prune_expr_location (tree *tp, int *walk_subtrees, void *)
+{
+  if (EXPR_P (*tp))
+    SET_EXPR_LOCATION (*tp, UNKNOWN_LOCATION);
+  else
+    *walk_subtrees = 0;
+  return NULL_TREE;
+}
+
+/* Similar to unshare_expr but also prune all expression locations
+   from EXPR.  */
+
+tree
+unshare_expr_without_location (tree expr)
+{
+  walk_tree (&expr, mostly_copy_tree_r, NULL, NULL);
+  if (EXPR_P (expr))
+    walk_tree (&expr, prune_expr_location, NULL, NULL);
+  return expr;
+}
 \f
 /* WRAPPER is a code such as BIND_EXPR or CLEANUP_POINT_EXPR which can both
    contain statements and have a value.  Assign its value to a temporary
index 4f887a0..d225b85 100644 (file)
@@ -295,31 +295,6 @@ ipa_print_all_jump_functions (FILE *f)
     }
 }
 
-/* Worker for prune_expression_for_jf.  */
-
-static tree
-prune_expression_for_jf_1 (tree *tp, int *walk_subtrees, void *)
-{
-  if (EXPR_P (*tp))
-    SET_EXPR_LOCATION (*tp, UNKNOWN_LOCATION);
-  else
-    *walk_subtrees = 0;
-  return NULL_TREE;
-}
-
-/* Return the expression tree EXPR unshared and with location stripped off.  */
-
-static tree
-prune_expression_for_jf (tree exp)
-{
-  if (EXPR_P (exp))
-    {
-      exp = unshare_expr (exp);
-      walk_tree (&exp, prune_expression_for_jf_1, NULL, NULL);
-    }
-  return exp;
-}
-
 /* Set JFUNC to be a known type jump function.  */
 
 static void
@@ -341,7 +316,7 @@ ipa_set_jf_constant (struct ipa_jump_func *jfunc, tree constant)
   if (constant && EXPR_P (constant))
     SET_EXPR_LOCATION (constant, UNKNOWN_LOCATION);
   jfunc->type = IPA_JF_CONST;
-  jfunc->value.constant = prune_expression_for_jf (constant);
+  jfunc->value.constant = unshare_expr_without_location (constant);
 }
 
 /* Set JFUNC to be a simple pass-through jump function.  */
@@ -363,7 +338,7 @@ ipa_set_jf_arith_pass_through (struct ipa_jump_func *jfunc, int formal_id,
                               tree operand, enum tree_code operation)
 {
   jfunc->type = IPA_JF_PASS_THROUGH;
-  jfunc->value.pass_through.operand = prune_expression_for_jf (operand);
+  jfunc->value.pass_through.operand = unshare_expr_without_location (operand);
   jfunc->value.pass_through.formal_id = formal_id;
   jfunc->value.pass_through.operation = operation;
   jfunc->value.pass_through.agg_preserved = false;
@@ -1385,7 +1360,7 @@ determine_known_aggregate_parts (gimple call, tree arg,
            {
              struct ipa_agg_jf_item item;
              item.offset = list->offset - arg_offset;
-             item.value = prune_expression_for_jf (list->constant);
+             item.value = unshare_expr_without_location (list->constant);
              jfunc->agg.items->quick_push (item);
            }
          list = list->next;
index 81693bf..8ae2361 100644 (file)
@@ -1,3 +1,9 @@
+2012-12-19  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/55736
+       PR tree-optimization/55703
+       * gcc.dg/lto/pr55703_0.c: New testcase.
+
 2012-12-19  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/55730
diff --git a/gcc/testsuite/gcc.dg/lto/pr55703_0.c b/gcc/testsuite/gcc.dg/lto/pr55703_0.c
new file mode 100644 (file)
index 0000000..1c4e04b
--- /dev/null
@@ -0,0 +1,59 @@
+/* { dg-lto-do run } */
+/* { dg-lto-options { { -O2 -flto -fno-tree-copy-prop -fno-tree-dce } } } */
+
+int try (int num) {
+  __label__ lab1, lab2, lab3, lab4, lab5, lab6, default_lab;
+
+  void *do_switch (int num) {
+    switch(num) {
+    case 1:
+      return &&lab1;
+    case 2:
+      return &&lab2;
+    case 3:
+      return &&lab3;
+    case 4:
+      return &&lab4;
+    case 5:
+      return &&lab5;
+    case 6:
+      return &&lab6;
+    default:
+      return &&default_lab;
+    }
+  }
+
+  goto *do_switch (num);
+
+ lab1:
+  return 1;
+
+ lab2:
+  return 2;
+
+ lab3:
+  return 3;
+
+ lab4:
+  return 4;
+
+ lab5:
+  return 5;
+
+ lab6:
+  return 6;
+
+ default_lab:
+  return -1;
+}
+
+main()
+{
+  int i;
+  for (i = 1; i <= 6; i++)
+    {
+      if (try (i) != i)
+       __builtin_abort();
+    }
+  __builtin_exit(0);
+}
index 9eed5e0..d250a94 100644 (file)
@@ -873,7 +873,8 @@ build_constructors (gimple swtch, struct switch_conv_info *info)
              constructor_elt elt;
 
              elt.index = int_const_binop (MINUS_EXPR, pos, info->range_min);
-             elt.value = info->default_values[k];
+             elt.value
+               = unshare_expr_without_location (info->default_values[k]);
              info->constructors[k]->quick_push (elt);
            }
 
@@ -899,7 +900,7 @@ build_constructors (gimple swtch, struct switch_conv_info *info)
              constructor_elt elt;
 
              elt.index = int_const_binop (MINUS_EXPR, pos, info->range_min);
-             elt.value = val;
+             elt.value = unshare_expr_without_location (val);
              info->constructors[j]->quick_push (elt);
 
              pos = int_const_binop (PLUS_EXPR, pos, integer_one_node);
index 01e81b2..b68328e 100644 (file)
@@ -5606,6 +5606,7 @@ extern void change_decl_assembler_name (tree, tree);
 \f
 /* In gimplify.c */
 extern tree unshare_expr (tree);
+extern tree unshare_expr_without_location (tree);
 \f
 /* In stmt.c */