]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Don't duplicate setup code cost when do group-candidate cost calucalution.
authorhongtao.liu <hongtao.liu@intel.com>
Wed, 5 Mar 2025 11:25:32 +0000 (12:25 +0100)
committerliuhongt <hongtao.liu@intel.com>
Tue, 24 Jun 2025 08:14:32 +0000 (01:14 -0700)
-  /* Uses in a group can share setup code, so only add setup cost once.  */
-  cost -= cost.scratch;

It looks like the original code took into account avoiding double
counting, but unfortunately cost is reset inside the follow loop which
invalidates the upper code, and makes same setup code cost duplicated in
each use of the group.

The patch fix the issue. It can also improve 548.exchange_r by 6% with
-march=x86-64-v3 -O2 due to better ivopt on EMR.

No big performance impact for SPEC2017 on graviton4/SPR with -mcpu=native
-Ofast -fomit-framepointer -flto=auto.

gcc/ChangeLog:

PR target/115842
* tree-ssa-loop-ivopts.cc (determine_group_iv_cost_address):
Don't recalculate inv_expr when group-candidate cost
calucalution.

gcc/tree-ssa-loop-ivopts.cc

index a2150818a43fb59137b10578999475c2e3e1f9f5..8a6726f198898051c9bb981aa949c6d8696e88e5 100644 (file)
@@ -5015,8 +5015,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++)
     {
@@ -5032,7 +5030,12 @@ determine_group_iv_cost_address (struct ivopts_data *data,
            if (!inv_exprs)
              inv_exprs = BITMAP_ALLOC (NULL);
 
-           bitmap_set_bit (inv_exprs, inv_expr->id);
+           /* 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;
     }