]> gcc.gnu.org Git - gcc.git/commitdiff
re PR middle-end/26198 (Unfolded comparison after cfg_cleanup)
authorRichard Guenther <rguenther@suse.de>
Fri, 12 Oct 2007 08:42:13 +0000 (08:42 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 12 Oct 2007 08:42:13 +0000 (08:42 +0000)
2007-10-12  Richard Guenther  <rguenther@suse.de>

PR middle-end/26198
* tree-ssa-forwprop.c (can_propagate_from): Do not propagate from
a rhs with side-effects or which is a load.
(forward_propagate_into_cond): Also try combining both operands.

* gcc.dg/tree-ssa/forwprop-3.c: New testcase.
* gcc.c-torture/execute/20071011-1.c: Likewise.
* gcc.dg/tree-ssa/ssa-pre-9.c: Adjust.

From-SVN: r129256

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/20071011-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/forwprop-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-9.c
gcc/tree-ssa-forwprop.c

index 28590a6c41b07d7d2573d2de4805d650214606ae..9abace31683d90ee6afb42ba6cf7adb8cad28cf7 100644 (file)
@@ -1,3 +1,10 @@
+2007-10-12  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/26198
+       * tree-ssa-forwprop.c (can_propagate_from): Do not propagate from
+       a rhs with side-effects or which is a load.
+       (forward_propagate_into_cond): Also try combining both operands.
+
 2007-10-12  Uros Bizjak  <ubizjak@gmail.com>
 
        PR tree-optimization/33742
index cacf0a9ed7dae503f2c8bb64031df11099d078ab..97d93ea5ef1527caeb1c7340cff99d722dcb3fee 100644 (file)
@@ -1,3 +1,10 @@
+2007-10-12  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/26198
+       * gcc.dg/tree-ssa/forwprop-3.c: New testcase.
+       * gcc.c-torture/execute/20071011-1.c: Likewise.
+       * gcc.dg/tree-ssa/ssa-pre-9.c: Adjust.
+
 2007-10-12  Uros Bizjak  <ubizjak@gmail.com>
 
        PR tree-optimization/33742
diff --git a/gcc/testsuite/gcc.c-torture/execute/20071011-1.c b/gcc/testsuite/gcc.c-torture/execute/20071011-1.c
new file mode 100644 (file)
index 0000000..6316585
--- /dev/null
@@ -0,0 +1,19 @@
+extern void abort(void);
+void foo(int *p)
+{
+  int x;
+  int y;
+  x = *p;
+  *p = 0;
+  y = *p;
+  if (x != y)
+    return;
+  abort ();
+}
+
+int main()
+{
+  int a = 1;
+  foo(&a);
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-3.c b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-3.c
new file mode 100644 (file)
index 0000000..0d26b8d
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-forwprop1" } */
+
+struct bar {
+  int a[2];
+};
+
+int foo(struct bar *x)
+{
+  int *p = &x->a[0];
+  int *q = &x->a[1];
+  if (p < q)
+    return 1;
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump "Replaced .p_. < q_.. with .1." "forwprop1" } } */
+/* { dg-final { cleanup-tree-dump "forwprop1" } } */
index 32e37b997039d21214e340cf93c79dbc97f53daf..30d968b7c536f927000d6b116354948bb685170b 100644 (file)
@@ -9,5 +9,5 @@ foo (unsigned long a)
     return 1;
   return 0;
 }
-/* { dg-final { scan-tree-dump-times "Eliminated: 1" 1 "fre"} } */
+/* { dg-final { scan-tree-dump-times "return 0;" 0 "fre"} } */
 /* { dg-final { cleanup-tree-dump "fre" } } */
index 3b72b6c44af8b40296e8ef691b504ff9a59508dc..b92a9f13f48662f23edce7ef8adda93d3339ab0f 100644 (file)
@@ -237,6 +237,14 @@ can_propagate_from (tree def_stmt)
 {
   tree rhs = GIMPLE_STMT_OPERAND (def_stmt, 1);
 
+  /* If the rhs has side-effects we cannot propagate from it.  */
+  if (TREE_SIDE_EFFECTS (rhs))
+    return false;
+
+  /* If the rhs is a load we cannot propagate from it.  */
+  if (REFERENCE_CLASS_P (rhs))
+    return false;
+
   /* We cannot propagate ssa names that occur in abnormal phi nodes.  */
   switch (TREE_CODE_LENGTH (TREE_CODE (rhs)))
     {
@@ -351,7 +359,7 @@ forward_propagate_into_cond (tree cond_expr, tree stmt)
   do {
     tree tmp = NULL_TREE;
     tree cond = COND_EXPR_COND (cond_expr);
-    tree name, def_stmt, rhs;
+    tree name, def_stmt, rhs0 = NULL_TREE, rhs1 = NULL_TREE;
     bool single_use_p;
 
     /* We can do tree combining on SSA_NAME and comparison expressions.  */
@@ -366,9 +374,9 @@ forward_propagate_into_cond (tree cond_expr, tree stmt)
            && can_propagate_from (def_stmt))
          {
            tree op1 = TREE_OPERAND (cond, 1);
-           rhs = GIMPLE_STMT_OPERAND (def_stmt, 1);
+           rhs0 = GIMPLE_STMT_OPERAND (def_stmt, 1);
            tmp = combine_cond_expr_cond (TREE_CODE (cond), boolean_type_node,
-                                         fold_convert (TREE_TYPE (op1), rhs),
+                                         fold_convert (TREE_TYPE (op1), rhs0),
                                          op1, !single_use_p);
          }
        /* If that wasn't successful, try the second operand.  */
@@ -382,12 +390,20 @@ forward_propagate_into_cond (tree cond_expr, tree stmt)
                || !can_propagate_from (def_stmt))
              return did_something;
 
-           rhs = GIMPLE_STMT_OPERAND (def_stmt, 1);
+           rhs1 = GIMPLE_STMT_OPERAND (def_stmt, 1);
            tmp = combine_cond_expr_cond (TREE_CODE (cond), boolean_type_node,
                                          op0,
-                                         fold_convert (TREE_TYPE (op0), rhs),
+                                         fold_convert (TREE_TYPE (op0), rhs1),
                                          !single_use_p);
          }
+       /* If that wasn't successful either, try both operands.  */
+       if (tmp == NULL_TREE
+           && rhs0 != NULL_TREE
+           && rhs1 != NULL_TREE)
+         tmp = combine_cond_expr_cond (TREE_CODE (cond), boolean_type_node,
+                                       rhs0,
+                                       fold_convert (TREE_TYPE (rhs0), rhs1),
+                                       !single_use_p);
       }
     else if (TREE_CODE (cond) == SSA_NAME)
       {
@@ -397,9 +413,9 @@ forward_propagate_into_cond (tree cond_expr, tree stmt)
            || !can_propagate_from (def_stmt))
          return did_something;
 
-       rhs = GIMPLE_STMT_OPERAND (def_stmt, 1);
-       tmp = combine_cond_expr_cond (NE_EXPR, boolean_type_node, rhs,
-                                     build_int_cst (TREE_TYPE (rhs), 0),
+       rhs0 = GIMPLE_STMT_OPERAND (def_stmt, 1);
+       tmp = combine_cond_expr_cond (NE_EXPR, boolean_type_node, rhs0,
+                                     build_int_cst (TREE_TYPE (rhs0), 0),
                                      false);
       }
 
This page took 0.186661 seconds and 5 git commands to generate.