On Tue, Nov 3, 2026 at 3:39 PM <[email protected]> wrote: > > From: Kyrylo Tkachov <[email protected]> > > Since r16-5042 simplify_vector_constructor accepts a CONSTRUCTOR element > that is a uniform vector and puts a splat of its scalar element at the > place of the CONSTRUCTOR. The splat is a new use of the scalar there. > When the scalar is an SSA name that occurs in an abnormal PHI and is > redefined before the CONSTRUCTOR, the live ranges of the two versions > overlap and out-of-SSA fails. For the new test at -O2 -mavx2, BB SLP > makes a CONSTRUCTOR of vectors and forwprop4 changes > > _50 = {a0_25(ab), a1_26(ab)}; > _49 = {a2_27(ab), a3_28(ab)}; > _48 = {x_18(D)(ab), x_18(D)(ab)}; > k_31(ab) = _30; > x_40(ab) = x_18(D)(ab) + 1.0e+0; > _1 = {_50, _49, _48, _48}; > > into > > x_40(ab) = x_18(D)(ab) + 1.0e+0; > _35 = {x_18(D)(ab), x_18(D)(ab), x_18(D)(ab), x_18(D)(ab), ...}; > _36 = VEC_PERM_EXPR <v_24(D), _35, { 0, 1, 2, 3, 12, 13, 14, 15 }>; > > On aarch64 the NEON folds of vdup_n_s32, vget_high_s32 and vcombine_s32 > give forwprop1 the same kind of CONSTRUCTOR at -O1 (the new aarch64 > test). > > Do not use such an SSA name for a vector element. A scalar element is > already used at the CONSTRUCTOR, so its splat does not extend its live > range. > > The new tests ICE on trunk: on x86_64 at -O2 with -mavx, -mavx2, > -march=x86-64-v3 or -march=x86-64-v4, on aarch64 at -O1, -O2 and -O3. > > Bootstrapped and regression tested on aarch64-unknown-linux-gnu and > x86_64-pc-linux-gnu. > Ok for trunk?
OK. Thanks, Richard. > Thanks, > Kyrill > > gcc/ChangeLog: > > PR tree-optimization/128406 > * tree-ssa-forwprop.cc (simplify_vector_constructor): Do not splat > the element of a uniform vector if it is an SSA name that occurs in > an abnormal PHI. > > gcc/testsuite/ChangeLog: > > PR tree-optimization/128406 > * gcc.target/aarch64/pr128406.c: New test. > * gcc.target/i386/pr128406.c: New test. > > Signed-off-by: Kyrylo Tkachov <[email protected]> > --- > gcc/testsuite/gcc.target/aarch64/pr128406.c | 25 +++++++++++++++++++ > gcc/testsuite/gcc.target/i386/pr128406.c | 27 +++++++++++++++++++++ > gcc/tree-ssa-forwprop.cc | 8 +++++- > 3 files changed, 59 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/gcc.target/aarch64/pr128406.c > create mode 100644 gcc/testsuite/gcc.target/i386/pr128406.c > > diff --git a/gcc/testsuite/gcc.target/aarch64/pr128406.c > b/gcc/testsuite/gcc.target/aarch64/pr128406.c > new file mode 100644 > index 00000000000..56935d98f05 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/aarch64/pr128406.c > @@ -0,0 +1,25 @@ > +/* PR tree-optimization/128406 */ > +/* { dg-do compile } */ > +/* { dg-options "-O1" } */ > + > +#include <arm_neon.h> > + > +extern int rt (void) __attribute__ ((returns_twice)); > +extern void bar (void); > +extern void use (int32_t); > + > +/* y occurs in abnormal PHIs. The NEON folds give forwprop a CONSTRUCTOR > + of the high half of x and of the splat of y. A new splat of y at the > + CONSTRUCTOR would be a use of y after its redefinition. */ > + > +void > +f (int32x4_t *out, int32x4_t x, int32_t y) > +{ > + int32x2_t w = vdup_n_s32 (y); > + bar (); > + y = y * 3; > + *out = vcombine_s32 (vget_high_s32 (x), w); > + bar (); > + rt (); > + use (y); > +} > diff --git a/gcc/testsuite/gcc.target/i386/pr128406.c > b/gcc/testsuite/gcc.target/i386/pr128406.c > new file mode 100644 > index 00000000000..108eb300094 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/pr128406.c > @@ -0,0 +1,27 @@ > +/* PR tree-optimization/128406 */ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -mavx2" } */ > + > +typedef float v8sf __attribute__ ((vector_size (32))); > +extern int rt (void) __attribute__ ((returns_twice)); > +extern int get (void); > +extern void use (float, float, float, float, float, int); > + > +/* x and a0...a3 occur in abnormal PHIs. BB SLP changes the CONSTRUCTOR > + into a CONSTRUCTOR of vectors of a0...a3 and of x. A splat of x at the > + CONSTRUCTOR would be a use of x after its redefinition. */ > + > +void > +f (v8sf *out, v8sf v, float x) > +{ > + get (); > + float a0 = v[0], a1 = v[1], a2 = v[2], a3 = v[3]; > + int k = get (); > + float b0 = a0, b1 = a1, b2 = a2, b3 = a3; > + float y0 = x, y1 = x, y2 = x, y3 = x; > + x++; > + *out = (v8sf) { b0, b1, b2, b3, y0, y1, y2, y3 }; > + get (); > + rt (); > + use (x, a0, a1, a2, a3, k); > +} > diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc > index 44f92810d1c..f9be9118f5d 100644 > --- a/gcc/tree-ssa-forwprop.cc > +++ b/gcc/tree-ssa-forwprop.cc > @@ -5421,7 +5421,13 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi) > subelt = VECTOR_TYPE_P (TREE_TYPE (elt->value)) > ? ssa_uniform_vector_p (elt->value) > : elt->value; > - if (!subelt) > + if (!subelt > + /* The splat of the element of a uniform vector is a new use > + of that element. Do not extend the live range of an SSA > + name that occurs in an abnormal PHI. */ > + || (VECTOR_TYPE_P (TREE_TYPE (elt->value)) > + && TREE_CODE (subelt) == SSA_NAME > + && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (subelt))) > return false; > if (!one_nonconstant) > one_nonconstant = subelt; > -- > 2.54.0 (Apple Git-157) >
