Guo Jie <[email protected]> writes:
LGTM, please apply.
> The heterogeneous even/odd widening templates combine a zero-extended
> operand with a sign-extended operand and produce a <WVEC_HALF> result.
> The zero-extended operand correctly uses <WVEC_HALF>, but the
> sign-extended operand in simd_<optab>w_evod_<mode>_hetero incorrectly
> uses <WVEC>, i.e. the mode of the un-widened source vector.
>
> For a 64-bit element input such as V2DI, the malformed RTL is:
>
> (plus:V1TI
> (zero_extend:V1TI (vec_select:V2DI ...))
> (sign_extend:V2TI (vec_select:V2DI ...)))
>
> or the corresponding minus or mult expression. The sign extension must
> produce V1TI, not V2TI. The malformed RTL can assert in CSE while
> folding constant operands, or later in combine's simplify_subreg.
>
> gcc/ChangeLog:
>
> * config/loongarch/simd.md
> (simd_<optab>w_evod_<mode>_hetero): Use <WVEC_HALF> instead of
> <WVEC> for the result of the sign extension.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/loongarch/vector/lasx/hetero-widen-const.c: New test.
> * gcc.target/loongarch/vector/lsx/hetero-widen-const.c: New test.
> ---
> gcc/config/loongarch/simd.md | 2 +-
> .../loongarch/vector/lasx/hetero-widen-const.c | 13 +++++++++++++
> .../loongarch/vector/lsx/hetero-widen-const.c | 13 +++++++++++++
> 3 files changed, 27 insertions(+), 1 deletion(-)
> create mode 100644
> gcc/testsuite/gcc.target/loongarch/vector/lasx/hetero-widen-const.c
> create mode 100644
> gcc/testsuite/gcc.target/loongarch/vector/lsx/hetero-widen-const.c
>
> diff --git a/gcc/config/loongarch/simd.md b/gcc/config/loongarch/simd.md
> index 09e746c56e7..83c93ad8b54 100644
> --- a/gcc/config/loongarch/simd.md
> +++ b/gcc/config/loongarch/simd.md
> @@ -743,7 +743,7 @@ (define_insn "simd_<optab>w_evod_<mode>_hetero"
> (vec_select:<VEC_HALF>
> (match_operand:IVEC 1 "register_operand" "f")
> (match_operand:IVEC 3 "vect_par_cnst_even_or_odd_half")))
> - (sign_extend:<WVEC>
> + (sign_extend:<WVEC_HALF>
> (vec_select:<VEC_HALF>
> (match_operand:IVEC 2 "register_operand" "f")
> (match_dup 3)))))]
> diff --git
> a/gcc/testsuite/gcc.target/loongarch/vector/lasx/hetero-widen-const.c
> b/gcc/testsuite/gcc.target/loongarch/vector/lasx/hetero-widen-const.c
> new file mode 100644
> index 00000000000..15621f1886e
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/loongarch/vector/lasx/hetero-widen-const.c
> @@ -0,0 +1,13 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -mlasx" } */
> +
> +#include <lasxintrin.h>
> +
> +v4i64
> +test_xvaddwod_q_du_d (void)
> +{
> + v4u64 a = { 0, 0, 0, 0 };
> + v4i64 b = { -1, -1, -1, -1 };
> +
> + return __builtin_lasx_xvaddwod_q_du_d (a, b);
> +}
> diff --git
> a/gcc/testsuite/gcc.target/loongarch/vector/lsx/hetero-widen-const.c
> b/gcc/testsuite/gcc.target/loongarch/vector/lsx/hetero-widen-const.c
> new file mode 100644
> index 00000000000..be9712a3152
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/loongarch/vector/lsx/hetero-widen-const.c
> @@ -0,0 +1,13 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -mlsx" } */
> +
> +#include <lsxintrin.h>
> +
> +v2i64
> +test_vaddwod_q_du_d (void)
> +{
> + v2u64 a = { 0, 0 };
> + v2i64 b = { -1, -1 };
> +
> + return __builtin_lsx_vaddwod_q_du_d (a, b);
> +}