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

            Bug ID: 98526
           Summary: [11 Regression] Double-counting of reduction cost
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rsandifo at gcc dot gnu.org
                CC: rguenth at gcc dot gnu.org
  Target Milestone: ---

The vect_body cost of most reductions is added twice,
once in vect_model_reduction_cost and once in whichever
vectorizable_* routine handles the reduction statement.
E.g. for:

long
f (long *x, int n)
{
  long res = 0;
  for (int i = 0; i < n; ++i)
    res += x[i];
  return res;
}

we have:

0x3c40a60 _4 + res_14 1 times scalar_to_vec costs 1 in prologue
0x3c40a60 _4 + res_14 1 times vector_stmt costs 1 in body           <----
0x3c40a60 _4 + res_14 1 times vector_stmt costs 1 in epilogue
0x3c40a60 _4 + res_14 1 times vec_to_scalar costs 2 in epilogue
0x3c40a60 *_3 1 times vector_load costs 1 in body
0x3c40a60 _4 + res_14 1 times vector_stmt costs 1 in body           <----

I don't yet have a case where this tips the balance though.

Reply via email to