http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52868
--- Comment #1 from Igor Zamyatin <izamyatin at gmail dot com> 2012-04-19 13:09:07 UTC --- Experimental patch that fixes the regression: diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index 3c11c0e..9c04516 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -4112,6 +4112,7 @@ get_computation_cost_at (struct ivopts_data *data, else if (ratio == 1) { tree real_cbase = cbase; + int diff_cost, add_cost_val; /* Check to see if any adjustment is needed. */ if (cstepi == 0 && stmt_is_after_inc) @@ -4131,7 +4132,19 @@ get_computation_cost_at (struct ivopts_data *data, ubase, real_cbase, &symbol_present, &var_present, &offset, depends_on); + diff_cost = cost.cost; cost.cost /= avg_loop_niter (data->current_loop); + add_cost_val = add_cost (TYPE_MODE (ctype), data->speed); + /* do cost correction if address cost is small enough + and difference cost is high enough */ + if (address_p && diff_cost > add_cost_val + && get_address_cost (symbol_present, var_present, + offset, ratio, cstepi, + TYPE_MODE (TREE_TYPE (utype)), + TYPE_ADDR_SPACE (TREE_TYPE (utype)), + speed, stmt_is_after_inc, + can_autoinc).cost <= add_cost_val) + cost.cost += add_cost_val; } else if (address_p && !POINTER_TYPE_P (ctype) It also fixes the bwaves regression from http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52272