Hi,

Just has minor formatting nits:

On 29/10/26 2:06 pm, Surya Kumari Jangala wrote:
> Hi Mike,
> 
> Changes from v2:
>   - Removed 'dg-do compile' and 'dg-require-effective-target powerpc_vsx' from
>     the testcases.
> Changes from v1:
>   - Removed -mvsx option from the list of dg-options in the testcases.
> 
> Below patch is bootstrapped and regtested on powerpc64le-linux and 
> powerpc64-linux
> with no regressions.
> 
> Regards,
> Surya
> 
> rs6000: Inefficient vector splat of small V2DI constants [PR107757]
> 
> On P8, for vector splat of double word constants, specifically -1 and 1,
> gcc generates inefficient code. For -1, gcc generates two instructions
> (vspltisw and vupkhsw) whereas only one instruction (vspltisw) is
> sufficient. For constant 1, gcc generates a load of the constant from
> .rodata instead of the instructions vspltisw and vupkhsw.
> 
> The routine vspltisw_vupkhsw_constant_p() returns true if the constant
> can be synthesized with instructions vspltisw and vupkhsw. However, for
> constant 1, this routine returns false.
> 
> For constant -1, this routine returns true. Vector splat of -1 can be
> done with only one instruction, i.e., vspltisw. We do not need two
> instructions. Hence this routine should return false for -1.
> 
> With this patch, gcc generates only one instruction (vspltisw) for -1.
> And for constant 1, this patch generates two instructions (vspltisw and
> vupkhsw).
> 
> 2024-11-20  Surya Kumari Jangala  <[email protected]>
> 
> gcc/
>       PR target/107757
>       * config/rs6000/rs6000.cc (vspltisw_vupkhsw_constant_p):
>       Return false for -1 and return true for 1.

ChangeLog: The description can be wrapped further to maintain its limit.

> 
> gcc/testsuite/
>       PR target/107757
>       * gcc.target/powerpc/pr107757-1.c: New.
>       * gcc.target/powerpc/pr107757-2.c: New.
> ---
>  gcc/config/rs6000/rs6000.cc                   |  2 +-
>  gcc/testsuite/gcc.target/powerpc/pr107757-1.c | 12 ++++++++++++
>  gcc/testsuite/gcc.target/powerpc/pr107757-2.c | 11 +++++++++++
>  3 files changed, 24 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/powerpc/pr107757-1.c
>  create mode 100644 gcc/testsuite/gcc.target/powerpc/pr107757-2.c
> 
> diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
> index bd3250f656b..5bffa2294d6 100644
> --- a/gcc/config/rs6000/rs6000.cc
> +++ b/gcc/config/rs6000/rs6000.cc
> @@ -6760,7 +6760,7 @@ vspltisw_vupkhsw_constant_p (rtx op, machine_mode mode, 
> int *constant_ptr)
>      return false;
>  
>    value = INTVAL (elt);
> -  if (value == 0 || value == 1
> +  if (value == 0 || value == -1
>        || !EASY_VECTOR_15 (value))
>      return false;
>  
> diff --git a/gcc/testsuite/gcc.target/powerpc/pr107757-1.c 
> b/gcc/testsuite/gcc.target/powerpc/pr107757-1.c
> new file mode 100644
> index 00000000000..b33a2912b94
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/pr107757-1.c
> @@ -0,0 +1,12 @@
> +/* { dg-options "-mdejagnu-cpu=power8 -O2" } */
> +/* { dg-final { scan-assembler {\mvspltisw\M} } } */
> +/* { dg-final { scan-assembler {\mvupkhsw\M} } } */
> +/* { dg-final { scan-assembler-not {\mlvx\M} } } */
> +
> +#include <altivec.h>
> +
> +vector long long
> +foo ()
> +{
> +       return vec_splats (1LL);
> +}

The return statement appears to have inconsistent indentation.

> diff --git a/gcc/testsuite/gcc.target/powerpc/pr107757-2.c 
> b/gcc/testsuite/gcc.target/powerpc/pr107757-2.c
> new file mode 100644
> index 00000000000..4312049c20d
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/pr107757-2.c
> @@ -0,0 +1,11 @@
> +/* { dg-options "-mdejagnu-cpu=power8 -O2" } */
> +/* { dg-final { scan-assembler {\mvspltisw\M} } } */
> +/* { dg-final { scan-assembler-not {\mvupkhsw\M} } } */
> +
> +#include <altivec.h>
> +
> +vector long long
> +foo ()
> +{
> +      return vec_splats (~0LL);
> +}

Similar indentation issue

Also wanted to ask few things here,

#include <altivec.h>
vector long long foo()
{
   return vec_splats(~0LL);
}

vector long long foo1()
{
   return vec_splats(0LL);
}

Right with above patch we are generating this
foo:
        vspltisw 2,-1
        blr

foo1:
        vspltisw 2,0
        blr

instead of generating altivec is it fine to generate VSX? I'm not sure
about performance impact

foo:                                  
        xxleqv 34, 34, 34
        blr

foo1:                           
        xxlxor 34, 34, 34
        blr

According to the POWER10 User Manual, the latency figures are:

Latency  (min) (max)
xxlnor -   1     3 
xxleqv -   1     3
vspltisw - 3     4

The VSX logical instructions appear to have lower latency. Would it be worth
considering these instructions instead of vspltisw?

Thanks,
Jeevitha.

Reply via email to