------- Comment #9 from spop at gcc dot gnu dot org  2010-02-09 04:57 -------
Hi,

As suggested by Zdenek, here is a patch that lowers the cost of the IV when
it is compared against zero in a condition.  The fragile part of this patch is
that it
lowers the cost by a magical constant "10".  Would there be a more appropriate
way to compute the effect, or a better constant?

Thanks,
Sebastian and Changpeng Fang

diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 436e6ce..5050d0c 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -4089,6 +4089,7 @@ determine_use_iv_cost_condition (struct ivopts_data
*data,
   bitmap depends_on_elim = NULL, depends_on_express = NULL, depends_on;
   comp_cost elim_cost, express_cost, cost;
   bool ok;
+  tree *control_var, *bound_cst;

   /* Only consider real candidates.  */
   if (!cand->iv)
@@ -4110,9 +4111,17 @@ determine_use_iv_cost_condition (struct ivopts_data
*data,

   /* Try expressing the original giv.  If it is compared with an invariant,
      note that we cannot get rid of it.  */
-  ok = extract_cond_operands (data, use->stmt, NULL, NULL, NULL, &cmp_iv);
+  ok = extract_cond_operands (data, use->stmt, &control_var, &bound_cst,
+                             NULL, &cmp_iv);
   gcc_assert (ok);

+  /* When the condition is a comparison of the candidate IV against
+     zero, prefer this IV.  */
+  if (integer_zerop (*bound_cst)
+      && (operand_equal_p (*control_var, cand->var_after, 0)
+         || operand_equal_p (*control_var, cand->var_before, 0)))
+    elim_cost.cost -= 10;
+
   express_cost = get_computation_cost (data, use, cand, false,
                                       &depends_on_express, NULL);
   fd_ivopts_data = data;


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40886

Reply via email to