Hi, When I going through the code, I spot this minor issue. When start_cand/orig_cand/third_cand have overall cost in order like "start_cand < third_cand < orig_cand", GCC chooses the third_cand instead of start_cand because we haven't set best_cost for start_cand. This is an obvious fix to it.
So is it OK? 2015-07-08 Bin Cheng <bin.ch...@arm.com> * tree-ssa-loop-ivopts.c (iv_ca_narrow): Update best_cost if start candidate has lower cost.
Index: gcc/tree-ssa-loop-ivopts.c =================================================================== --- gcc/tree-ssa-loop-ivopts.c (revision 225531) +++ gcc/tree-ssa-loop-ivopts.c (working copy) @@ -6064,6 +6066,13 @@ iv_ca_narrow (struct ivopts_data *data, struct iv_ best_cost = iv_ca_cost (ivs); /* Start narrowing with START. */ new_cp = get_use_iv_cost (data, use, start); + if (new_cp != NULL) + { + iv_ca_set_cp (data, ivs, use, new_cp); + acost = iv_ca_cost (ivs); + if (compare_costs (acost, best_cost) < 0) + best_cost = acost; + } if (data->consider_all_candidates) {