]> git.ipfire.org Git - thirdparty/gcc.git/commit
forwprop: allow subvectors in simplify_vector_constructor ()
authorArtemiy Volkov <artemiy.volkov@arm.com>
Sat, 1 Nov 2025 17:17:15 +0000 (17:17 +0000)
committerArtemiy Volkov <artemiy.volkov@arm.com>
Wed, 5 Nov 2025 10:38:51 +0000 (10:38 +0000)
commit470411f44f51d9ef85bfcf3a8f9cb25344dd243f
treeeda10a564a74638d0e59aa5da17f58b5e0145c36
parent7c4f8ae20cc09e8732739ac839c845ba8c2991c0
forwprop: allow subvectors in simplify_vector_constructor ()

This is an attempt to fix
https://gcc.gnu.org/pipermail/gcc-patches/2025-October/697879.html in the
middle-end; the motivation in that patch was to teach gcc to compile:

int16x8_t foo (int16x8_t x)
{
  return vcombine_s16 (vget_high_s16 (x), vget_low_s16 (x));
}

into one instruction:

foo:
        ext     v0.16b, v0.16b, v0.16b, #8
        ret

rather than the two we are generating now:

foo:
        dup     d31, v0.d[1]
        uzp1    v0.2d, v31.2d, v0.2d
        ret

Instead of adding a define_insn in the backend, this patch relaxes the
precondition of tree-ssa-forwprop.cc:simplify_vector_constructor () to
accept subvectors as constructor elements.  During initial argument
processing (ll. 3817-3916), subvectors are decomposed into individual
elements before populating the ELTS array; this allows the rest of the
function to remain unchanged.  Special handling is also implemented for
constant and splat subvector elements of a constructor (the latter with
the use of ssa_uniform_vector_p () from tree-vect-generic.cc, which this
patch moves to tree.cc).

Add GIMPLE tests to gcc.dg/tree-ssa demonstrating the intended behavior
with various combinations of subvectors as constructor arguments,
including constant and splat subvectors; also add some aarch64-specific
tests to show that the change leads to us picking the "ext" instruction
for the resulting VEC_PERM_EXPR.

Bootstrapped and regtested on aarch64 and x86_64, regtested on aarch64_be.

gcc/ChangeLog:

* tree-ssa-forwprop.cc (simplify_vector_constructor): Support
vector constructor elements.
* tree-vect-generic.cc (ssa_uniform_vector_p): Make non-static and
move ...
* tree.cc (ssa_uniform_vector_p): ... here.
* tree.h (ssa_uniform_vector_p): Declare it.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/forwprop-43.c: New test.
* gcc.target/aarch64/simd/combine_ext.c: New test.
gcc/testsuite/gcc.dg/tree-ssa/forwprop-43.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/simd/combine_ext.c [new file with mode: 0644]
gcc/tree-ssa-forwprop.cc
gcc/tree-vect-generic.cc
gcc/tree.cc
gcc/tree.h