diff mbox series

PR90763: PowerPC vec_xl_len should take const argument.

Message ID 5551fcf34d8c04c32ee7d8a7498f1328a94a733a.camel@vnet.ibm.com
State New
Headers show
Series PR90763: PowerPC vec_xl_len should take const argument. | expand

Commit Message

will schmidt Feb. 25, 2020, 6:15 p.m. UTC
PR90763: PowerPC vec_xl_len should take const argument.

Hi,

  Adds some logic in altivec_resolve_overloaded_builtin() to handle the
scenario where const <foo>* arguments are passed in to the vec_xl_len()
builtin.
The existing logic to remove const from pointers does not kick in since
the return type is not itself a pointer type.
    
Regtested ok.
OK for master?
    
Thanks,
-Will
    
    2020-02-24:  Will Schmidt  <will_schmidt@vnet.ibm.com>
    
    gcc/
    	PR target/90763
    	* config/rs6000/rs6000-c.c (altivec_resolve_overloaded_builtin): Add
    	clause to handle P9V_BUILTIN_VEC_LXVL with const arguments.
    
    testsuite/
    	PR target/90763
    	* gcc.target/powerpc/pr90763: New.

Comments

Segher Boessenkool Feb. 25, 2020, 8:29 p.m. UTC | #1
Hi!

On Tue, Feb 25, 2020 at 12:15:52PM -0600, will schmidt wrote:
>   Adds some logic in altivec_resolve_overloaded_builtin() to handle the
> scenario where const <foo>* arguments are passed in to the vec_xl_len()
> builtin.
> The existing logic to remove const from pointers does not kick in since
> the return type is not itself a pointer type.

>     2020-02-24:  Will Schmidt  <will_schmidt@vnet.ibm.com>

No colon here.

>     gcc/
>     	PR target/90763
>     	* config/rs6000/rs6000-c.c (altivec_resolve_overloaded_builtin): Add
>     	clause to handle P9V_BUILTIN_VEC_LXVL with const arguments.
>     
>     testsuite/
>     	PR target/90763
>     	* gcc.target/powerpc/pr90763: New.

(That is not the actual filename, please fix).

> 
> diff --git a/gcc/config/rs6000/rs6000-c.c b/gcc/config/rs6000/rs6000-c.c
> index 37c74cf..9ad8309 100644
> --- a/gcc/config/rs6000/rs6000-c.c
> +++ b/gcc/config/rs6000/rs6000-c.c
> @@ -1636,10 +1636,24 @@ altivec_resolve_overloaded_builtin (location_t loc, tree fndecl,
>  	  type = build_pointer_type (build_qualified_type (TREE_TYPE (type),
>  							   0));
>  	  arg = fold_convert (type, arg);
>  	}
>  
> +      /* For P9V_BUILTIN_VEC_LXVL, convert any const * to its non constant
> +	 equivalent to simplify the overload matching below.  */
> +      if (fcode == P9V_BUILTIN_VEC_LXVL)
> +	{
> +	  if (POINTER_TYPE_P (type)
> +	      && (TYPE_QUALS (TREE_TYPE (type)) != 0)
> +	      && TYPE_READONLY (TREE_TYPE (type)))

The test for TYPE_QUALS is superfluous, you test for TYPE_READONLY anyway.

> +	    {
> +	      type = build_pointer_type (build_qualified_type (
> +						TREE_TYPE (type),0));
> +	      arg = fold_convert (type, arg);
> +	    }
> +	}
> +
>        args[n] = arg;
>        types[n] = type;
>      }
>  
>    /* If the number of arguments did not match the prototype, return NULL
> diff --git a/gcc/testsuite/gcc.target/powerpc/pr90763.c b/gcc/testsuite/gcc.target/powerpc/pr90763.c
> new file mode 100644
> index 0000000..ec0e56e
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/pr90763.c
> @@ -0,0 +1,87 @@
> +/* { dg-require-effective-target powerpc_p9vector_ok } */
> +/* { dg-options "-mcpu=power9" } */

Add -O2 as well?

Okay for trunk with those tweaks.  Does this need backports as well?

Thanks!


Segher
will schmidt March 9, 2020, 2:48 p.m. UTC | #2
On Tue, 2020-02-25 at 12:15 -0600, will schmidt wrote:
> PR90763: PowerPC vec_xl_len should take const argument.

ping!   :-)

thanks
-Will

> 
> Hi,
> 
>   Adds some logic in altivec_resolve_overloaded_builtin() to handle
> the
> scenario where const <foo>* arguments are passed in to the
> vec_xl_len()
> builtin.
> The existing logic to remove const from pointers does not kick in
> since
> the return type is not itself a pointer type.
> 
> Regtested ok.
> OK for master?
> 
> Thanks,
> -Will
> 
>     2020-02-24:  Will Schmidt  <will_schmidt@vnet.ibm.com>
> 
>     gcc/
>     	PR target/90763
>     	* config/rs6000/rs6000-c.c
> (altivec_resolve_overloaded_builtin): Add
>     	clause to handle P9V_BUILTIN_VEC_LXVL with const arguments.
> 
>     testsuite/
>     	PR target/90763
>     	* gcc.target/powerpc/pr90763: New.
> 
> diff --git a/gcc/config/rs6000/rs6000-c.c b/gcc/config/rs6000/rs6000-
> c.c
> index 37c74cf..9ad8309 100644
> --- a/gcc/config/rs6000/rs6000-c.c
> +++ b/gcc/config/rs6000/rs6000-c.c
> @@ -1636,10 +1636,24 @@ altivec_resolve_overloaded_builtin
> (location_t loc, tree fndecl,
>  	  type = build_pointer_type (build_qualified_type (TREE_TYPE
> (type),
>  							   0));
>  	  arg = fold_convert (type, arg);
>  	}
> 
> +      /* For P9V_BUILTIN_VEC_LXVL, convert any const * to its non
> constant
> +	 equivalent to simplify the overload matching below.  */
> +      if (fcode == P9V_BUILTIN_VEC_LXVL)
> +	{
> +	  if (POINTER_TYPE_P (type)
> +	      && (TYPE_QUALS (TREE_TYPE (type)) != 0)
> +	      && TYPE_READONLY (TREE_TYPE (type)))
> +	    {
> +	      type = build_pointer_type (build_qualified_type (
> +						TREE_TYPE (type),0));
> +	      arg = fold_convert (type, arg);
> +	    }
> +	}
> +
>        args[n] = arg;
>        types[n] = type;
>      }
> 
>    /* If the number of arguments did not match the prototype, return
> NULL
> diff --git a/gcc/testsuite/gcc.target/powerpc/pr90763.c
> b/gcc/testsuite/gcc.target/powerpc/pr90763.c
> new file mode 100644
> index 0000000..ec0e56e
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/pr90763.c
> @@ -0,0 +1,87 @@
> +/* { dg-require-effective-target powerpc_p9vector_ok } */
> +/* { dg-options "-mcpu=power9" } */
> +
> +/* PR90763: PowerPC vec_xl_len should take const.
> +*/
> +
> +#include <altivec.h>
> +
> +vector unsigned char vec_load_uc(unsigned char *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +vector unsigned char vec_load_const_uc(const unsigned char *p, int
> num) {
> +    return vec_xl_len(p, num);
> +}
> +vector signed char vec_load_sc(signed char *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +vector signed char vec_load_const_sc(const signed char *p, int num)
> {
> +    return vec_xl_len(p, num);
> +}
> +
> +vector signed short vec_load_ss(signed short *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +vector signed short vec_load_const_ss(const signed short *p, int
> num) {
> +    return vec_xl_len(p, num);
> +}
> +vector unsigned short vec_load_us(unsigned short *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +vector unsigned short vec_load_const_us(const unsigned short *p, int
> num) {
> +    return vec_xl_len(p, num);
> +}
> +
> +vector signed int vec_load_si(signed int *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +vector signed int vec_load_const_si(const signed int *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +vector unsigned int vec_load_ui(unsigned int *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +vector unsigned int vec_load_const_ui(const unsigned int *p, int
> num) {
> +    return vec_xl_len(p, num);
> +}
> +
> +vector signed long long vec_load_sll(signed long long *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +vector signed long long vec_load_const_sll(const signed long long
> *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +vector unsigned long long vec_load_ull(unsigned long long *p, int
> num) {
> +    return vec_xl_len(p, num);
> +}
> +vector unsigned long long vec_load_const_ull(const unsigned long
> long *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +
> +vector signed __int128 vec_load_si128(signed __int128 *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +vector signed __int128 vec_load_const_si128(const signed __int128
> *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +vector unsigned __int128 vec_load_ui128(unsigned __int128 *p, int
> num) {
> +    return vec_xl_len(p, num);
> +}
> +vector unsigned __int128 vec_load_const_ui128(const unsigned
> __int128 *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +
> +vector float vec_load_f(float *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +vector float vec_load_const_f(const float *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +
> +vector double vec_load_d(double *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +vector double vec_load_const_d(const double *p, int num) {
> +    return vec_xl_len(p, num);
> +}
> +
>
Segher Boessenkool March 9, 2020, 5:45 p.m. UTC | #3
On Mon, Mar 09, 2020 at 09:48:01AM -0500, will schmidt wrote:
> On Tue, 2020-02-25 at 12:15 -0600, will schmidt wrote:
> > PR90763: PowerPC vec_xl_len should take const argument.
> 
> ping!   :-)

https://gcc.gnu.org/pipermail/gcc-patches/2020-February/540969.html


Segher
diff mbox series

Patch

diff --git a/gcc/config/rs6000/rs6000-c.c b/gcc/config/rs6000/rs6000-c.c
index 37c74cf..9ad8309 100644
--- a/gcc/config/rs6000/rs6000-c.c
+++ b/gcc/config/rs6000/rs6000-c.c
@@ -1636,10 +1636,24 @@  altivec_resolve_overloaded_builtin (location_t loc, tree fndecl,
 	  type = build_pointer_type (build_qualified_type (TREE_TYPE (type),
 							   0));
 	  arg = fold_convert (type, arg);
 	}
 
+      /* For P9V_BUILTIN_VEC_LXVL, convert any const * to its non constant
+	 equivalent to simplify the overload matching below.  */
+      if (fcode == P9V_BUILTIN_VEC_LXVL)
+	{
+	  if (POINTER_TYPE_P (type)
+	      && (TYPE_QUALS (TREE_TYPE (type)) != 0)
+	      && TYPE_READONLY (TREE_TYPE (type)))
+	    {
+	      type = build_pointer_type (build_qualified_type (
+						TREE_TYPE (type),0));
+	      arg = fold_convert (type, arg);
+	    }
+	}
+
       args[n] = arg;
       types[n] = type;
     }
 
   /* If the number of arguments did not match the prototype, return NULL
diff --git a/gcc/testsuite/gcc.target/powerpc/pr90763.c b/gcc/testsuite/gcc.target/powerpc/pr90763.c
new file mode 100644
index 0000000..ec0e56e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr90763.c
@@ -0,0 +1,87 @@ 
+/* { dg-require-effective-target powerpc_p9vector_ok } */
+/* { dg-options "-mcpu=power9" } */
+
+/* PR90763: PowerPC vec_xl_len should take const.
+*/
+
+#include <altivec.h>
+
+vector unsigned char vec_load_uc(unsigned char *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector unsigned char vec_load_const_uc(const unsigned char *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector signed char vec_load_sc(signed char *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector signed char vec_load_const_sc(const signed char *p, int num) {
+    return vec_xl_len(p, num);
+}
+
+vector signed short vec_load_ss(signed short *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector signed short vec_load_const_ss(const signed short *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector unsigned short vec_load_us(unsigned short *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector unsigned short vec_load_const_us(const unsigned short *p, int num) {
+    return vec_xl_len(p, num);
+}
+
+vector signed int vec_load_si(signed int *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector signed int vec_load_const_si(const signed int *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector unsigned int vec_load_ui(unsigned int *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector unsigned int vec_load_const_ui(const unsigned int *p, int num) {
+    return vec_xl_len(p, num);
+}
+
+vector signed long long vec_load_sll(signed long long *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector signed long long vec_load_const_sll(const signed long long *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector unsigned long long vec_load_ull(unsigned long long *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector unsigned long long vec_load_const_ull(const unsigned long long *p, int num) {
+    return vec_xl_len(p, num);
+}
+
+vector signed __int128 vec_load_si128(signed __int128 *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector signed __int128 vec_load_const_si128(const signed __int128 *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector unsigned __int128 vec_load_ui128(unsigned __int128 *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector unsigned __int128 vec_load_const_ui128(const unsigned __int128 *p, int num) {
+    return vec_xl_len(p, num);
+}
+
+vector float vec_load_f(float *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector float vec_load_const_f(const float *p, int num) {
+    return vec_xl_len(p, num);
+}
+
+vector double vec_load_d(double *p, int num) {
+    return vec_xl_len(p, num);
+}
+vector double vec_load_const_d(const double *p, int num) {
+    return vec_xl_len(p, num);
+}
+