When a loop loads a narrow type and then does arithmetic in a wider type,
GCC on x86_64 loads a full vector and widens it with vextract/unpack
sequences. This series lets the vectorizer emit a single fused
load-and-extend instruction (vpmovzx/vpmovsx with a memory operand)
instead.
Patch 1/2 adds a new internal function IFN_VEC_LOAD_EXTEND with its
optab, and the x86 sse.md patterns that implement it. It has no
users yet, so there is no code generation change.
Patch 2/2 adds a vectorizer pattern that recognizes a load followed by
a widening conversion and replaces it with .VEC_LOAD_EXTEND when the
target supports it.
Changes since v1:
- Reworked the approach as suggested: v1 narrowed the load's vector
type in the SLP tree (vect_optimize_slp_widening_loads);
v2 represents the fused operation explicitly as an internal function
and optab.
v1: https://gcc.gnu.org/pipermail/gcc-patches/2026-September/730496.html
Bootstrapped and tested on x86.
Sridevi (2):
Enable extended load optimization
Enable extended load optimization
gcc/config/i386/sse.md | 30 +++
gcc/internal-fn.cc | 23 +++
gcc/internal-fn.def | 3 +
gcc/optabs.def | 2 +
gcc/testsuite/gcc.dg/vect/widening-load-u8.c | 20 ++
.../gcc.target/i386/vect-epilogues-2b.c | 4 +-
.../gcc.target/i386/vect-epilogues-3.c | 1 -
.../gcc.target/i386/vect-load-extend-1.c | 24 +++
gcc/testsuite/gcc.target/i386/vect-unpack-2.c | 2 +-
gcc/tree-vect-loop.cc | 9 +
gcc/tree-vect-patterns.cc | 190 ++++++++++++++++++
gcc/tree-vect-slp.cc | 22 +-
gcc/tree-vect-stmts.cc | 59 +++++-
13 files changed, 381 insertions(+), 8 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/vect/widening-load-u8.c
create mode 100644 gcc/testsuite/gcc.target/i386/vect-load-extend-1.c
--
2.34.1