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

--- Comment #2 from Jin Kang <jin_kang66 at 163 dot com> ---
(In reply to Richard Biener from comment #1)
> Confirmed, practically only GCC 17+ is affected since only after that x86-64
> uses compare-costs and the epilog mode chosen is suggested_epilog_mode.

Yes, indeed. Here is a minimal reproducer that demonstrates the missed early
pruning on x86-64 trunk:

Testcase (test.c):
------------------
void test(int *__restrict__ a, int *__restrict__ b, int *__restrict__ c, int n)
{
    for (int i = 0; i < n; i++) {
        a[i] = b[i] + c[i];
    }
}

How to reproduce:
-----------------
gcc -O3 -march=znver4 -mtune-ctrl=^avx512_masked_epilogues \
    --param vect-partial-vector-usage=0 --param vect-epilogues-nomask=1 \
    -fopt-info-vec-all -c test.c

Relevant output:
----------------
test.c:2:23: note:  ***** Choosing vector mode V16SI
...
(Epilogue 1 chooses V32QI, VF=8)
...
test.c:2:23: note:  ***** Skipping vector mode V64QI, which would repeat the
analysis for V16SI
test.c:2:23: note:  ***** Re-trying epilogue analysis with vector mode V32QI
test.c:2:23: note:  operating on full vectors for epilogue loop.
test.c:2:23: missed:  Vectorization factor too high for epilogue loop.
test.c:2:23: note:  ***** Analysis failed with vector mode V32QI
test.c:2:23: note:  ***** Re-trying epilogue analysis with vector mode V16QI
test.c:2:23: note:  ***** Analysis succeeded with vector mode V16QI

Explanation:
------------
1. The main loop selects V16SI (VF = 16) and Epilogue 1 selects V32QI (VF = 8).
2. When analyzing for Epilogue 2 (parent VF = 8), V64QI (VF = 16) is skipped,
but V32QI (cached VF = 8) is checked against first_vinfo_vf (16) instead of
LOOP_VINFO_VECT_FACTOR (orig_loop_vinfo) (8).
3. Because maybe_ge (8, 16) is false, V32QI is not pruned early, triggering a
redundant vect_analyze_loop_1 pass before being rejected in vect_analyze_loop_2
("Vectorization factor too high for epilogue loop.").

Reply via email to