[Bug tree-optimization/101944] suboptimal SLP for reduced case from namd_r

linkw at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Aug 17 09:29:49 GMT 2021


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

--- Comment #1 from Kewen Lin <linkw at gcc dot gnu.org> ---
The original costing shows the vectorized version wins, by checking
the costings, it missed to model the cost of lane extraction, the
patch was posted in:
https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577422.html

With the proposed adjustment above, the costings become to:

reduc.c:24:34: note: Cost model analysis for part in loop 0:
  Vector cost: 17
  Scalar cost: 17

Now we consider vectorization is still profitable when both cost are
equal, so the SLP still performs.

One thing can make it different is that: when we do costing, math
optimization doesn't happen, there are no FMA-style operations, but
finally some multiply and subtraction is optimized to FMS. If
costing for scalar faces two multiply-and-sub (counted as 2) instead
of two multiplies and subtractions (counted as 4), vs. vector costing
1 instead of 2. It ends up with scalar 15 vs. vector 16.

But it seems not practical since we can't predict the later processing
well, I tried to hack pass_optimize_widening_mul to run before slp,
I saw it failed earlier.


More information about the Gcc-bugs mailing list