[backport from gcc-4.7/trunk ] gcc/ 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.1/gcc/tree-flow.h.~1~ 2011-05-11 15:07:54.000000000 +0200 +++ gcc-4.6.1/gcc/tree-flow.h 2011-09-23 12:07:16.000000000 +0200 @@ -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.1/gcc/tree-ssa-dom.c.~1~ 2011-02-14 18:59:10.000000000 +0100 +++ gcc-4.6.1/gcc/tree-ssa-dom.c 2011-09-23 12:07:16.000000000 +0200 @@ -1397,9 +1397,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; @@ -1411,12 +1412,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.1/gcc/tree-ssa-forwprop.c.~1~ 2011-04-22 20:53:30.000000000 +0200 +++ gcc-4.6.1/gcc/tree-ssa-forwprop.c 2011-09-23 12:05:40.000000000 +0200 @@ -1995,6 +1995,7 @@ tree_ssa_forward_propagate_single_use_va && can_propagate_from (stmt)) { if (TREE_CODE (gimple_assign_rhs2 (stmt)) == INTEGER_CST + && !simple_iv_increment_p (stmt) /* ??? Better adjust the interface to that function instead of building new trees here. */ && forward_propagate_addr_expr