https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115842

--- Comment #6 from Hongtao Liu <liuhongt at gcc dot gnu.org> ---
 I noticed some double-counting of cost in group-candidate (regarding loop
invariant expressions), this modification reduces the number of instructions
executed by ~8% for exchange_r binary compiled with -march=x86-64-v3 -O2.


diff --git a/gcc/tree-ssa-loop-ivopts.cc b/gcc/tree-ssa-loop-ivopts.cc
index e37b24062f7..d68d54d299e 100644
--- a/gcc/tree-ssa-loop-ivopts.cc
+++ b/gcc/tree-ssa-loop-ivopts.cc
@@ -5016,8 +5016,6 @@ determine_group_iv_cost_address (struct ivopts_data
*data,
        sum_cost = infinite_cost;
     }

-  /* Uses in a group can share setup code, so only add setup cost once.  */
-  cost -= cost.scratch;
   /* Compute and add costs for rest uses of this group.  */
   for (i = 1; i < group->vuses.length () && !sum_cost.infinite_cost_p (); i++)
     {
@@ -5033,6 +5031,10 @@ determine_group_iv_cost_address (struct ivopts_data
*data,
            if (!inv_exprs)
              inv_exprs = BITMAP_ALLOC (NULL);

+           /* Uses in a group can share setup code, so only add setup cost
once.  */
+           if (bitmap_bit_p (inv_exprs, inv_expr->id))
+             cost -= cost.scratch;
+           else
            bitmap_set_bit (inv_exprs, inv_expr->id);
          }
       sum_cost += cost;

Reply via email to