https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122069
--- Comment #13 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Kyrylo Tkachov <[email protected]>: https://gcc.gnu.org/g:d0850a968d4e85b2d257b0e78fa61b1021137ede commit r17-3474-gd0850a968d4e85b2d257b0e78fa61b1021137ede Author: Kyrylo Tkachov <[email protected]> Date: Wed Aug 12 17:57:30 2026 +0200 middle-end: Try intermediate types for widening sums [PR122069] vect_recog_widen_sum_pattern currently queries the widening-sum optab only for the scalar input type in the source. This misses target patterns that start at an intermediate precision. For example, AArch64 SVE has a VNx2DI <- VNx8HI widening sum but no VNx2DI <- VNx8QI widening sum. Keep the exact input query and operand first. If the query fails, try successively wider full-element integer types up to half the accumulator width. Preserve the input signedness and use vect_convert_input to make the intermediate conversion. The recognized pattern can then use: patt_1 = (short int) byte; patt_2 = patt_1 w+ sum_0; For an unsigned byte-to-64-bit reduction on AArch64 SVE, the old main loop processes VL / 64 input bytes per iteration: cntd x3 whilelo p7.d, xzr, x1 movi d30, #0 ptrue p6.b, all .L3: ld1b z29.d, p7/z, [x0, x2] add x2, x2, x3 add z30.d, p7/m, z30.d, z29.d whilelo p7.d, x2, x1 b.any .L3 uaddv d31, p6, z30.d The new main loop processes VL / 16 input bytes per iteration: cnth x0 movi d31, #0 ptrue p7.b, all mov z29.h, #1 .L4: ld1b z30.h, p7/z, [x3, x2] add x2, x2, x0 udot z31.d, z30.h, z29.h cmp x4, x2 bcs .L4 uaddv d31, p7, z31.d For the same number of input bytes, the old main loop executes four times and issues four widened loads and four vector adds. The new loop executes once and issues one widened load and one dot product. The signed form similarly uses LD1SB and SDOT. Direct byte-to-32-bit dot products do not change. Bootstrapped and tested on aarch64-none-linux-gnu. gcc/ChangeLog: PR middle-end/122069 * tree-vect-patterns.cc (vect_recog_widen_sum_pattern): Try wider intermediate input types. gcc/testsuite/ChangeLog: PR middle-end/122069 * gcc.target/aarch64/sve/reduc_3_costly.c: Update the expected number of horizontal reductions. * gcc.target/aarch64/sve/widen_sum_1.c: New test. Signed-off-by: Kyrylo Tkachov <[email protected]>
