Hi Bin, This patch follows your suggestion, to avoid use infinite cost iv cand to rewrite. In order to allow other IV cands to be considered, zeroing the iv cand cost if its users are only doloop uses. (See the typical case in previous reply.) Could you please have a look? Thanks in advance! Kewen ------------- gcc/ChangeLog 2019-07-23 Kewen Lin PR middle-end/80791 * target.def (have_count_reg_decr_p): New hook. * doc/tm.texi.in (TARGET_HAVE_COUNT_REG_DECR_P): New hook. * doc/tm.texi: Regenerate. * config/rs6000/rs6000.c (rs6000_have_count_reg_decr_p): New function. (TARGET_HAVE_COUNT_REG_DECR_P): New macro. * tree-ssa-loop-ivopts.c (adjust_group_iv_cost_for_doloop): New function. (find_doloop_use): Likewise. (record_group): Init doloop_p. (determine_group_iv_cost): Call adjust_group_iv_cost_for_doloop. (tree_ssa_iv_optimize_loop): Call function have_count_reg_decr_p, generic_predict_doloop_p and find_doloop_use. (generic_predict_doloop_p): Update attribute. (iv_ca_set_no_cp): Adjust cand cost handling for doloop. (iv_ca_set_cp): Likewise. (iv_ca_new): Init n_cand_doloop_uses. (iv_ca_free): Free n_cand_doloop_uses. gcc/testsuite/ChangeLog 2019-07-23 Kewen Lin PR middle-end/80791 * gcc.dg/tree-ssa/ivopts-lt.c: Adjust.