re PR tree-optimization/50213 (Regression in space-optimized code relative to 4.5.x)
authorRichard Guenther <rguenther@suse.de>
Wed, 7 Sep 2011 11:28:39 +0000 (11:28 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 7 Sep 2011 11:28:39 +0000 (11:28 +0000)
2011-09-07  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/50213
* tree-flow.h (simple_iv_increment_p): Declare.
* tree-ssa-dom.c (simple_iv_increment_p): Export.  Also handle
POINTER_PLUS_EXPR.
* tree-ssa-forwprop.c (ssa_forward_propagate_and_combine): Do
not propagate simple IV counter increments.

From-SVN: r178633

gcc/ChangeLog
gcc/tree-flow.h
gcc/tree-ssa-dom.c
gcc/tree-ssa-forwprop.c

index 4fccde3b980cea493dacbb24f90b3163d65579a2..224e1a551b856a43f9f724fa36a12a619d8fad98 100644 (file)
@@ -1,3 +1,12 @@
+2011-09-07  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/50213
+       * tree-flow.h (simple_iv_increment_p): Declare.
+       * tree-ssa-dom.c (simple_iv_increment_p): Export.  Also handle
+       POINTER_PLUS_EXPR.
+       * tree-ssa-forwprop.c (ssa_forward_propagate_and_combine): Do
+       not propagate simple IV counter increments.
+
 2011-09-07  Eric Botcazou  <ebotcazou@adacore.com>
            Iain Sandoe  <iains@gcc.gnu.org>
 
index 28c0d8aabbc121e6a31675a4baff73773e394d01..d4bf54cbe693e4e46fa22c694c2f886d11fc0678 100644 (file)
@@ -597,6 +597,7 @@ extern void dump_dominator_optimization_stats (FILE *);
 extern void debug_dominator_optimization_stats (void);
 int loop_depth_of_name (tree);
 tree degenerate_phi_result (gimple);
+bool simple_iv_increment_p (gimple);
 
 /* In tree-ssa-copy.c  */
 extern void propagate_value (use_operand_p, tree);
index 7a00c8ad937af10f4dc422a98b13e81b40bfb81c..18923aede7bf1ebb4cde64cd5d668d27b62d7896 100644 (file)
@@ -1409,9 +1409,10 @@ record_equality (tree x, tree y)
    i_1 = phi (..., i_2)
    i_2 = i_1 +/- ...  */
 
-static bool
+bool
 simple_iv_increment_p (gimple stmt)
 {
+  enum tree_code code;
   tree lhs, preinc;
   gimple phi;
   size_t i;
@@ -1423,12 +1424,13 @@ simple_iv_increment_p (gimple stmt)
   if (TREE_CODE (lhs) != SSA_NAME)
     return false;
 
-  if (gimple_assign_rhs_code (stmt) != PLUS_EXPR
-      && gimple_assign_rhs_code (stmt) != MINUS_EXPR)
+  code = gimple_assign_rhs_code (stmt);
+  if (code != PLUS_EXPR
+      && code != MINUS_EXPR
+      && code != POINTER_PLUS_EXPR)
     return false;
 
   preinc = gimple_assign_rhs1 (stmt);
-
   if (TREE_CODE (preinc) != SSA_NAME)
     return false;
 
index 89d6239836bb754617dd1209960f8ed0b4a18379..ae37095d88e5df3ab38935f2d4dd4f05fca09638 100644 (file)
@@ -2377,21 +2377,23 @@ ssa_forward_propagate_and_combine (void)
              else
                gsi_next (&gsi);
            }
-         else if (code == POINTER_PLUS_EXPR && can_propagate_from (stmt))
+         else if (code == POINTER_PLUS_EXPR)
            {
-             if (TREE_CODE (gimple_assign_rhs2 (stmt)) == INTEGER_CST
+             tree off = gimple_assign_rhs2 (stmt);
+             if (TREE_CODE (off) == INTEGER_CST
+                 && can_propagate_from (stmt)
+                 && !simple_iv_increment_p (stmt)
                  /* ???  Better adjust the interface to that function
                     instead of building new trees here.  */
                  && forward_propagate_addr_expr
-                 (lhs,
-                  build1 (ADDR_EXPR,
-                          TREE_TYPE (rhs),
-                          fold_build2 (MEM_REF,
-                                       TREE_TYPE (TREE_TYPE (rhs)),
-                                       rhs,
-                                       fold_convert
-                                       (ptr_type_node,
-                                        gimple_assign_rhs2 (stmt))))))
+                      (lhs,
+                       build1_loc (gimple_location (stmt),
+                                   ADDR_EXPR, TREE_TYPE (rhs),
+                                   fold_build2 (MEM_REF,
+                                                TREE_TYPE (TREE_TYPE (rhs)),
+                                                rhs,
+                                                fold_convert (ptr_type_node,
+                                                              off)))))
                {
                  release_defs (stmt);
                  todoflags |= TODO_remove_unused_locals;