[adjusted to apply after pr15256-2-pr18041 rather than before ] From 21a41ea517c2e60d3a910aca8012a2c0d57b1005 Mon Sep 17 00:00:00 2001 From: Peter A. Bigot Date: Thu, 22 Sep 2011 09:22:25 -0500 Subject: [PATCH] SF 3412886 pre-patch pr50213/tree-optimization This is a back-port of the following upstream commit. commit cd22a7968a89e465b934b7b2b9ff685a9652601b Author: rguenth Date: Wed Sep 7 11:28:39 2011 +0000 2011-09-07 Richard Guenther 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. --- gcc-4.6.2/gcc/tree-flow.h.~1~ 2011-05-11 15:07:54.000000000 +0200 +++ gcc-4.6.2/gcc/tree-flow.h 2012-01-14 15:11:07.000000000 +0100 @@ -601,6 +601,7 @@ extern void dump_dominator_optimization_ 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); --- gcc-4.6.2/gcc/tree-ssa-dom.c.~1~ 2011-06-30 21:35:45.000000000 +0200 +++ gcc-4.6.2/gcc/tree-ssa-dom.c 2012-01-14 15:11:07.000000000 +0100 @@ -1396,9 +1396,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; @@ -1410,12 +1411,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; --- gcc-4.6.2/gcc/tree-ssa-forwprop.c.~1~ 2012-01-14 15:07:18.000000000 +0100 +++ gcc-4.6.2/gcc/tree-ssa-forwprop.c 2012-01-14 15:11:07.000000000 +0100 @@ -2262,10 +2262,12 @@ tree_ssa_forward_propagate_single_use_va 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 @@ -2277,7 +2279,7 @@ tree_ssa_forward_propagate_single_use_va rhs, fold_convert (ptr_type_node, - gimple_assign_rhs2 (stmt)))))) + off))))) { release_defs (stmt); todoflags |= TODO_remove_unused_locals;