My colleagues and I have been working on the GCC port for the Qualcomm Hexagon. Along the way I noticed that we were getting poor results from the ivopts pass no matter how we adjusted the target-specific RTX costs. In many cases ivopts was coming up with candidate use costs that seemed completely inconsistent with the target cost model. On further inspection, I found what appears to be a whole bunch of bugs in the way ivopts is computing address costs: (1) While the address cost computation is assuming in some situations that pre/post increment/decrement addressing will be used if supported by the target, it isn't actually using the target's address cost for such forms -- instead, just the cost of the form that would be used if autoinc weren't available/applicable. (2) The computation to determine which multiplier values are supported by target addressing modes is constructing an address rtx of the form (reg * ratio) to do the tests. This isn't a valid address RTX on Hexagon, although both (reg + reg * ratio) and (sym + reg * ratio) are. Because it's choosing the wrong address form to probe with, it thinks that the target doesn't support multipliers at all and is incorrectly tacking on an extra cost for them. I also note that it's assuming that the same set of ratios are supported by all three address forms that can potentially include them, and that all valid ratios have the same cost. (3) The computation to determine the range of valid constant offsets for address forms that can include them is probing the upper end of the range using constants of the form ((1< gcc/ * tree-ssa-loop-ivopts.c (comp_cost): Make complexity field signed. Update comments to indicate this is for addressing mode complexity. (new_cost): Make signedness of parameters match comp_cost fields. (compare_costs): Prefer higher complexity, not lower, per documentation of TARGET_ADDRESS_COST. (multiplier_allowed_in_address_p): Use (+ (* reg1 ratio) reg2) to probe for valid ratios, rather than just (* reg1 ratio). (get_address_cost): Rewrite to eliminate precomputation and caching. Use target's address cost for autoinc forms if possible. Only attempt sym_present -> var_present cost conversion if the sym_present form is not legitimate; amortize setup cost over loop iterations. Adjust complexity computation. (get_computation_cost_at): Adjust call to get_address_cost. Do not mess with complexity for non-address expressions. (determine_use_iv_cost_address): Initialize can_autoinc. (autoinc_possible_for_pair): Likewise.