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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Robin Dapp <[email protected]>:

https://gcc.gnu.org/g:4e244f93dbc479830e4293a68220f9a2ccc203ac

commit r17-6850-g4e244f93dbc479830e4293a68220f9a2ccc203ac
Author: Robin Dapp <[email protected]>
Date:   Fri Nov 27 11:58:22 2026 +0100

    RISC-V: Compute shift factor for poly_int synthesis [PR129054].

    Back when we introduced the loop to compute the division/shift factor
    for poly-int synthesis we kept it for clarity reasons.  I suggested a
    loop-free version without realizing that it doesn't have the loop's
    drawback.
    What we need to do is divide/shift VLENB until we can multiply it by an
    integer to reach FACTOR, e.g. for a factor of 3 we divide VLENB = 8 by 8
    and multiply by 3.  Which division factors to try depends on a hardcoded
    MAX_POLY_VARIANT = 64.  In the PR we have a factor of 1 and VLENB = 128
    (at _zvl1024b).  Therefore VLENB / MAX_POLY_VARIANT never reaches 1 and
    we can't compute FACTOR.

    For this patch, I cleaned up my old approach

          div_factor = wi::ctz (factor) - wi::ctz (vlenb);
          if (div_factor >= 0)
            div_factor = 1;
          else
            div_factor = 1 << -div_factor;

    realizing that we can swap FACTOR and VLENB which avoids the negation of
    div_factor.  Also we can compute the shift amount directly instead of
    going exact_log2 (1 << div_factor).  MAX_POLY_VARIANT can go as well.

            PR target/129054

    gcc/ChangeLog:

            * config/riscv/riscv.cc (riscv_legitimize_poly_move): Use ctz
            instead of loop.
            * config/riscv/riscv.h (MAX_POLY_VARIANT): Remove

    gcc/testsuite/ChangeLog:

            * gcc.target/riscv/rvv/autovec/pr129054.c: New test.

Reply via email to