Re: [PATCH, rs6000] PR89765: Multiple problems with vec-insert implementation on PowerPC

2019-05-01 Thread Segher Boessenkool
On Tue, Apr 30, 2019 at 11:04:10AM -0500, Kelvin Nilsen wrote:
> 
> In combination with a related recently committed patch 
> (https://gcc.gnu.org/ml/gcc-patches/2019-04/msg00989.html), the attached 
> patch resolves the issues described in this problem report.  This patch also 
> includes tests to exercise the previously committed patch.
> 
> This patch includes redundant content from patch PR89424 
> (https://gcc.gnu.org/ml/gcc-patches/2019-04/msg00994.html), which has been 
> already been approved by Segher for trunk and backports to GCC 7 and 8 but is 
> awaiting GCC 9 release.
> 
> The patch has been bootstrapped and tested without regressions on 
> powerpc64le-unknown-linux-gnu (both P8 and P9) and on 
> powerpc64-unknown-linux-gnu (P7 and P8, both -m32 and -m64).
> 
> Segher: After GCC9 release, is this ok for trunk and backports to GCC 7 and 
> GCC8?

Okay for trunk.  If it tests fine everywhere, and GCC 9.1 has been released,
okay for 9, and after that, okay for 8 and 7, too.

Thanks!


Segher


Re: [PATCH, rs6000] PR89765: Multiple problems with vec-insert implementation on PowerPC

2019-04-30 Thread Jakub Jelinek
On Tue, Apr 30, 2019 at 11:04:10AM -0500, Kelvin Nilsen wrote:
> 
> In combination with a related recently committed patch 
> (https://gcc.gnu.org/ml/gcc-patches/2019-04/msg00989.html), the attached 
> patch resolves the issues described in this problem report.  This patch also 
> includes tests to exercise the previously committed patch.
> 
> This patch includes redundant content from patch PR89424 
> (https://gcc.gnu.org/ml/gcc-patches/2019-04/msg00994.html), which has been 
> already been approved by Segher for trunk and backports to GCC 7 and 8 but is 
> awaiting GCC 9 release.
> 
> The patch has been bootstrapped and tested without regressions on 
> powerpc64le-unknown-linux-gnu (both P8 and P9) and on 
> powerpc64-unknown-linux-gnu (P7 and P8, both -m32 and -m64).
> 
> Segher: After GCC9 release, is this ok for trunk and backports to GCC 7 and 
> GCC8?
> 
> Jakub or Richi: Is this patch and the redundant PR89424 patch ok for 
> backports to GCC9?

I'm not against backporting it for GCC 9.2, but would strongly prefer not to
backport before GCC 9.1 is released.  At least from what I've seen, you get
many wrong-code issues with the V1TImode on powerpc since many years ago,
so I don't see why it couldn't wait another week.

The only changes to GCC 9.1 now should be severe blockers.

> 2019-04-30  Kelvin Nilsen  
> 
>   PR target/89765
>   * config/rs6000/rs6000-c.c (altivec_resolve_overloaded_builtin):
>   In handling of ALTIVEC_BUILTIN_VEC_INSERT, use modular arithmetic
>   to compute vector element selector for both constant and variable
>   operands.
>   * config/rs6000/rs6000.c (rs6000_expand_vector_extract): Add case
>   to handle V1TImode vectors.

Jakub


[PATCH, rs6000] PR89765: Multiple problems with vec-insert implementation on PowerPC

2019-04-30 Thread Kelvin Nilsen


In combination with a related recently committed patch 
(https://gcc.gnu.org/ml/gcc-patches/2019-04/msg00989.html), the attached patch 
resolves the issues described in this problem report.  This patch also includes 
tests to exercise the previously committed patch.

This patch includes redundant content from patch PR89424 
(https://gcc.gnu.org/ml/gcc-patches/2019-04/msg00994.html), which has been 
already been approved by Segher for trunk and backports to GCC 7 and 8 but is 
awaiting GCC 9 release.

The patch has been bootstrapped and tested without regressions on 
powerpc64le-unknown-linux-gnu (both P8 and P9) and on 
powerpc64-unknown-linux-gnu (P7 and P8, both -m32 and -m64).

Segher: After GCC9 release, is this ok for trunk and backports to GCC 7 and 
GCC8?

Jakub or Richi: Is this patch and the redundant PR89424 patch ok for backports 
to GCC9?

gcc/ChangeLog:

2019-04-30  Kelvin Nilsen  

PR target/89765
* config/rs6000/rs6000-c.c (altivec_resolve_overloaded_builtin):
In handling of ALTIVEC_BUILTIN_VEC_INSERT, use modular arithmetic
to compute vector element selector for both constant and variable
operands.
* config/rs6000/rs6000.c (rs6000_expand_vector_extract): Add case
to handle V1TImode vectors.

gcc/testsuite/ChangeLog:

2019-04-30  Kelvin Nilsen  

PR target/89765
* gcc.target/powerpc/pr89765-mc.c: New test.
* gcc.target/powerpc/vsx-builtin-10c.c: New test.
* gcc.target/powerpc/vsx-builtin-10d.c: New test.
* gcc.target/powerpc/vsx-builtin-11c.c: New test.
* gcc.target/powerpc/vsx-builtin-11d.c: New test.
* gcc.target/powerpc/vsx-builtin-12c.c: New test.
* gcc.target/powerpc/vsx-builtin-12d.c: New test.
* gcc.target/powerpc/vsx-builtin-13c.c: New test.
* gcc.target/powerpc/vsx-builtin-13d.c: New test.
* gcc.target/powerpc/vsx-builtin-14c.c: New test.
* gcc.target/powerpc/vsx-builtin-14d.c: New test.
* gcc.target/powerpc/vsx-builtin-15c.c: New test.
* gcc.target/powerpc/vsx-builtin-15d.c: New test.
* gcc.target/powerpc/vsx-builtin-16c.c: New test.
* gcc.target/powerpc/vsx-builtin-16d.c: New test.
* gcc.target/powerpc/vsx-builtin-17c.c: New test.
* gcc.target/powerpc/vsx-builtin-17d.c: New test.
* gcc.target/powerpc/vsx-builtin-18c.c: New test.
* gcc.target/powerpc/vsx-builtin-18d.c: New test.
* gcc.target/powerpc/vsx-builtin-19c.c: New test.
* gcc.target/powerpc/vsx-builtin-19d.c: New test.
* gcc.target/powerpc/vsx-builtin-20c.c: New test.
* gcc.target/powerpc/vsx-builtin-20d.c: New test.
* gcc.target/powerpc/vsx-builtin-9c.c: New test.
* gcc.target/powerpc/vsx-builtin-9d.c: New test.
* gcc.target/powerpc/vsx-builtin-13a.c (PR89424): Define this
macro to increase coverage of test.
* gcc.target/powerpc/vsx-builtin-13b.c (PR89424): Likewise.
* gcc.target/powerpc/vsx-builtin-20a.c (PR89424): Likewise.
* gcc.target/powerpc/vsx-builtin-20b.c (PR89424): Likewise.

Index: gcc/config/rs6000/rs6000-c.c
===
--- gcc/config/rs6000/rs6000-c.c(revision 270584)
+++ gcc/config/rs6000/rs6000-c.c(working copy)
@@ -6736,11 +6736,13 @@ altivec_resolve_overloaded_builtin (location_t loc
   /* If we can use the VSX xxpermdi instruction, use that for insert.  */
   mode = TYPE_MODE (arg1_type);
   if ((mode == V2DFmode || mode == V2DImode) && VECTOR_UNIT_VSX_P (mode)
- && TREE_CODE (arg2) == INTEGER_CST
- && wi::ltu_p (wi::to_wide (arg2), 2))
+ && TREE_CODE (arg2) == INTEGER_CST)
{
+ wide_int selector = wi::to_wide (arg2);
+ selector = wi::umod_trunc (selector, 2);
  tree call = NULL_TREE;
 
+ arg2 = wide_int_to_tree (TREE_TYPE (arg2), selector);
  if (mode == V2DFmode)
call = rs6000_builtin_decls[VSX_BUILTIN_VEC_SET_V2DF];
  else if (mode == V2DImode)
@@ -6752,11 +6754,12 @@ altivec_resolve_overloaded_builtin (location_t loc
return build_call_expr (call, 3, arg1, arg0, arg2);
}
   else if (mode == V1TImode && VECTOR_UNIT_VSX_P (mode)
-  && TREE_CODE (arg2) == INTEGER_CST
-  && wi::eq_p (wi::to_wide (arg2), 0))
+  && TREE_CODE (arg2) == INTEGER_CST)
{
  tree call = rs6000_builtin_decls[VSX_BUILTIN_VEC_SET_V1TI];
+ wide_int selector = wi::zero(32);
 
+ arg2 = wide_int_to_tree (TREE_TYPE (arg2), selector);
  /* Note, __builtin_vec_insert_ has vector and scalar types
 reversed.  */
  return build_call_expr (call, 3, arg1, arg0, arg2);
@@ -6764,10 +6767,13 @@ altivec_resolve_overloaded_builtin (location_t loc
 
   /* Build *(((arg1_inner_type*)&(vector type){arg1})+arg2) = arg0. */
   arg1_inner_type = TREE_TYPE