https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127510
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|GCC is not able to |GCC vectorizes
|vectorize "std::for_each_n" |"std::for_each_n" loop
|loop taking on random |taking on random access
|access iterator with more |iterator with more than one
|than one pointers. |pointers as uncounted loop
Ever confirmed|0 |1
Last reconfirmed| |2026-09-21
Status|UNCONFIRMED |NEW
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
The real issue is:
t.C:65:71: note: Cost model analysis:
Vector inside of loop cost: 140
Vector prologue cost: 620
Vector epilogue cost: 392
Scalar iteration cost: 92
Scalar outside cost: 8
Vector outside cost: 1012
prologue iterations: 4
epilogue iterations: 4
Calculated minimum iters for profitability: 12
t.C:65:71: note: Runtime profitability threshold = 12
t.C:65:71: note: Static estimate profitability threshold = 12
Estimating # of iterations of loop 1
t.C:65:71: note: not vectorized: no loop iteration estimate on the uncounted
loop and not trivially profitable.
t.C:65:71: missed: Loop costings may not be worthwhile.
which is because we analyze this as uncounted loop (what Andrea says).
With -fno-vect-cost-model you get versioning for mutual alignment and
peeling and the core loop body ends up
.L153:
vmovdqa64 (%rdi,%rax,8), %zmm0
vpaddq %zmm5, %zmm4, %zmm4
vpaddq %zmm5, %zmm3, %zmm3
vpaddq %zmm5, %zmm2, %zmm2
vpaddq 0(%r13,%rax,8), %zmm0, %zmm0
vpcmpuq $5, %zmm7, %zmm0, %k1
vpsubq %zmm7, %zmm0, %zmm0{%k1}
vmovdqu64 %zmm0, (%r8,%rax,8)
addq $8, %rax
.L6:
vpaddq %zmm1, %zmm2, %zmm6
vpaddq %zmm1, %zmm3, %zmm0
vpcmpq $0, %zmm8, %zmm6, %k1
vpcmpq $0, %zmm9, %zmm0, %k1{%k1}
vpaddq %zmm1, %zmm4, %zmm0
vpcmpq $0, %zmm10, %zmm0, %k0{%k1}
kortestb %k0, %k0
je .L153
but we really want to handle &&/|| in niter analysis.