Re: [PATCH, rs6000] Fold vector addition built-ins in GIMPLE

2016-12-19 Thread Will Schmidt
On Tue, 2016-12-06 at 09:59 +0100, Andreas Schwab wrote:
> On Dez 05 2016, Bill Schmidt  wrote:
> 
> > What's your target triple?
> 
> http://gcc.gnu.org/ml/gcc-testresults/2016-12/msg00471.html
> 
> Andreas.
> 

I *suspect* this is fixable with the addition of this dg- directive to
the fold-vec-add-7.c test.  
+/* { dg-require-effective-target int128 } */

Still working on a recreate locally to see if I can verify that.. 

Looks like Andreas' build is configured with " 
configure flags: --prefix=/usr --build=powerpc64-suse-linux
--enable-checking=release --enable-shared --with-system-zlib CFLAGS='-O2
-g' CXXFLAGS='-O2 -g' --with-cpu-64=power4 --enable-secureplt
--with-long-double-128  "



Thanks,
-Will



Re: [PATCH, rs6000] Fold vector addition built-ins in GIMPLE

2016-12-06 Thread Andreas Schwab
On Dez 05 2016, Bill Schmidt  wrote:

> What's your target triple?

http://gcc.gnu.org/ml/gcc-testresults/2016-12/msg00471.html

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: [PATCH, rs6000] Fold vector addition built-ins in GIMPLE

2016-12-05 Thread Bill Schmidt
What's your target triple?

> On Dec 4, 2016, at 6:36 AM, Andreas Schwab  wrote:
> 
> On Nov 01 2016, Bill Schmidt  wrote:
> 
>>  * gcc.target/powerpc/fold-vec-add-7.c: New.
> 
> spawn -ignore SIGHUP /daten/gcc/gcc-20161203/Build/gcc/xgcc 
> -B/daten/gcc/gcc-20161203/Build/gcc/ 
> /daten/gcc/gcc-20161203/gcc/testsuite/gcc.target/powerpc/fold-vec-add-7.c 
> -m32 -fno-diagnostics-show-caret -fdiagnostics-color=never -maltivec -mvsx 
> -mpower8-vector -ffat-lto-objects -S -o fold-vec-add-7.s.
> /daten/gcc/gcc-20161203/gcc/testsuite/gcc.target/powerpc/fold-vec-add-7.c:11:15:
>  error: '__int128' is not supported on this target.
> /daten/gcc/gcc-20161203/gcc/testsuite/gcc.target/powerpc/fold-vec-add-7.c:12:22:
>  error: '__int128' is not supported on this target.
> /daten/gcc/gcc-20161203/gcc/testsuite/gcc.target/powerpc/fold-vec-add-7.c:12:48:
>  error: '__int128' is not supported on this target.
> /daten/gcc/gcc-20161203/gcc/testsuite/gcc.target/powerpc/fold-vec-add-7.c:17:17:
>  error: '__int128' is not supported on this target.
> /daten/gcc/gcc-20161203/gcc/testsuite/gcc.target/powerpc/fold-vec-add-7.c:18:24:
>  error: '__int128' is not supported on this target.
> /daten/gcc/gcc-20161203/gcc/testsuite/gcc.target/powerpc/fold-vec-add-7.c:18:52:
>  error: '__int128' is not supported on this target.
> compiler exited with status 1
> FAIL: gcc.target/powerpc/fold-vec-add-7.c (test for excess errors)
> 
> Andreas.
> 
> -- 
> Andreas Schwab, sch...@linux-m68k.org
> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."
> 



Re: [PATCH, rs6000] Fold vector addition built-ins in GIMPLE

2016-12-04 Thread Andreas Schwab
On Nov 01 2016, Bill Schmidt  wrote:

>   * gcc.target/powerpc/fold-vec-add-7.c: New.

spawn -ignore SIGHUP /daten/gcc/gcc-20161203/Build/gcc/xgcc 
-B/daten/gcc/gcc-20161203/Build/gcc/ 
/daten/gcc/gcc-20161203/gcc/testsuite/gcc.target/powerpc/fold-vec-add-7.c -m32 
-fno-diagnostics-show-caret -fdiagnostics-color=never -maltivec -mvsx 
-mpower8-vector -ffat-lto-objects -S -o fold-vec-add-7.s.
/daten/gcc/gcc-20161203/gcc/testsuite/gcc.target/powerpc/fold-vec-add-7.c:11:15:
 error: '__int128' is not supported on this target.
/daten/gcc/gcc-20161203/gcc/testsuite/gcc.target/powerpc/fold-vec-add-7.c:12:22:
 error: '__int128' is not supported on this target.
/daten/gcc/gcc-20161203/gcc/testsuite/gcc.target/powerpc/fold-vec-add-7.c:12:48:
 error: '__int128' is not supported on this target.
/daten/gcc/gcc-20161203/gcc/testsuite/gcc.target/powerpc/fold-vec-add-7.c:17:17:
 error: '__int128' is not supported on this target.
/daten/gcc/gcc-20161203/gcc/testsuite/gcc.target/powerpc/fold-vec-add-7.c:18:24:
 error: '__int128' is not supported on this target.
/daten/gcc/gcc-20161203/gcc/testsuite/gcc.target/powerpc/fold-vec-add-7.c:18:52:
 error: '__int128' is not supported on this target.
compiler exited with status 1
FAIL: gcc.target/powerpc/fold-vec-add-7.c (test for excess errors)

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Re: [PATCH, rs6000] Fold vector addition built-ins in GIMPLE

2016-11-04 Thread Segher Boessenkool
Hi Bill,

On Tue, Nov 01, 2016 at 09:05:03PM -0500, Bill Schmidt wrote:
> As Jakub suggested in response to my *ahem* ornate patch for overloaded
> function built-ins, a much better approach is to use the existing
> machinery for overloading and then immediately fold the specific
> functions during gimplification.  There is a target hook available for
> this purpose that we have not previously used.  This patch demonstrates
> this functionality by implementing the target hook and folding vector
> addition built-ins within it.  Future patches will fold other such
> operations, improving the optimization available for many vector
> intrinsics.
> 
> Bootstrapped and tested on powerpc64le-unknown-linux-gnu with no
> regressions.  Is this ok for trunk?

This looks fine, please apply.

Thanks,


Segher


Re: [PATCH, rs6000] Fold vector addition built-ins in GIMPLE

2016-11-04 Thread Bill Schmidt
Just a note that the "-std=gnu11" option in the test cases in this patch is a 
leftover
from a previous version of the patch, which I'll plan to remove.  Sorry for the
oversight!

Bill

> On Nov 1, 2016, at 9:05 PM, Bill Schmidt  wrote:
> 
> Hi,
> 
> As Jakub suggested in response to my *ahem* ornate patch for overloaded
> function built-ins, a much better approach is to use the existing
> machinery for overloading and then immediately fold the specific
> functions during gimplification.  There is a target hook available for
> this purpose that we have not previously used.  This patch demonstrates
> this functionality by implementing the target hook and folding vector
> addition built-ins within it.  Future patches will fold other such
> operations, improving the optimization available for many vector
> intrinsics.
> 
> Bootstrapped and tested on powerpc64le-unknown-linux-gnu with no
> regressions.  Is this ok for trunk?
> 
> Thanks,
> Bill
> 
> 
> [gcc]
> 
> 2016-11-01  Bill Schmidt  
> 
>   * config/rs6000/rs6000.c (gimple-ssa.h): New #include.
>   (TARGET_GIMPLE_FOLD_BUILTIN): Define as
>   rs6000_gimple_fold_builtin.
>   (rs6000_gimple_fold_builtin): New function.  Add handling for
>   early expansion of vector addition builtins.
> 
> 
> [gcc/testsuite]
> 
> 2016-11-01  Bill Schmidt  
> 
>   * gcc.target/powerpc/fold-vec-add-1.c: New.
>   * gcc.target/powerpc/fold-vec-add-2.c: New.
>   * gcc.target/powerpc/fold-vec-add-3.c: New.
>   * gcc.target/powerpc/fold-vec-add-4.c: New.
>   * gcc.target/powerpc/fold-vec-add-5.c: New.
>   * gcc.target/powerpc/fold-vec-add-6.c: New.
>   * gcc.target/powerpc/fold-vec-add-7.c: New.
> 
> 
> Index: gcc/config/rs6000/rs6000.c
> ===
> --- gcc/config/rs6000/rs6000.c(revision 241624)
> +++ gcc/config/rs6000/rs6000.c(working copy)
> @@ -56,6 +56,7 @@
> #include "sched-int.h"
> #include "gimplify.h"
> #include "gimple-iterator.h"
> +#include "gimple-ssa.h"
> #include "gimple-walk.h"
> #include "intl.h"
> #include "params.h"
> @@ -1632,6 +1633,8 @@ static const struct attribute_spec rs6000_attribut
> 
> #undef TARGET_FOLD_BUILTIN
> #define TARGET_FOLD_BUILTIN rs6000_fold_builtin
> +#undef TARGET_GIMPLE_FOLD_BUILTIN
> +#define TARGET_GIMPLE_FOLD_BUILTIN rs6000_gimple_fold_builtin
> 
> #undef TARGET_EXPAND_BUILTIN
> #define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
> @@ -16337,6 +16340,46 @@ rs6000_fold_builtin (tree fndecl, int n_args ATTRI
> #endif
> }
> 
> +/* Fold a machine-dependent built-in in GIMPLE.  (For folding into
> +   a constant, use rs6000_fold_builtin.)  */
> +
> +bool
> +rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi)
> +{
> +  gimple *stmt = gsi_stmt (*gsi);
> +  tree fndecl = gimple_call_fndecl (stmt);
> +  gcc_checking_assert (fndecl && DECL_BUILT_IN_CLASS (fndecl) == 
> BUILT_IN_MD);
> +  enum rs6000_builtins fn_code
> += (enum rs6000_builtins) DECL_FUNCTION_CODE (fndecl);
> +  tree arg0, arg1, lhs;
> +
> +  switch (fn_code)
> +{
> +/* Flavors of vec_add.  We deliberately don't expand
> +   P8V_BUILTIN_VADDUQM as it gets lowered from V1TImode to
> +   TImode, resulting in much poorer code generation.  */
> +case ALTIVEC_BUILTIN_VADDUBM:
> +case ALTIVEC_BUILTIN_VADDUHM:
> +case ALTIVEC_BUILTIN_VADDUWM:
> +case P8V_BUILTIN_VADDUDM:
> +case ALTIVEC_BUILTIN_VADDFP:
> +case VSX_BUILTIN_XVADDDP:
> +  {
> + arg0 = gimple_call_arg (stmt, 0);
> + arg1 = gimple_call_arg (stmt, 1);
> + lhs = gimple_call_lhs (stmt);
> + gimple *g = gimple_build_assign (lhs, PLUS_EXPR, arg0, arg1);
> + gimple_set_location (g, gimple_location (stmt));
> + gsi_replace (gsi, g, true);
> + return true;
> +  }
> +default:
> +  break;
> +}
> +
> +  return false;
> +}
> +
> /* Expand an expression EXP that calls a built-in function,
>with result going to TARGET if that's convenient
>(and in mode MODE if that's convenient).
> Index: gcc/testsuite/gcc.target/powerpc/fold-vec-add-1.c
> ===
> --- gcc/testsuite/gcc.target/powerpc/fold-vec-add-1.c (revision 0)
> +++ gcc/testsuite/gcc.target/powerpc/fold-vec-add-1.c (working copy)
> @@ -0,0 +1,46 @@
> +/* Verify that overloaded built-ins for vec_add with char
> +   inputs produce the right results.  */
> +
> +/* { dg-do compile } */
> +/* { dg-require-effective-target powerpc_altivec_ok } */
> +/* { dg-additional-options "-std=gnu11" } */
> +
> +#include 
> +
> +vector signed char
> +test1 (vector bool char x, vector signed char y)
> +{
> +  return vec_add (x, y);
> +}
> +
> +vector signed char
> +test2 (vector signed char x, vector bool char y)
> +{
> +  return vec_add (x, y);
> +}
> +
> +vector signed char
> +test3 (vector signed char x, vector signed char y)
> +{
> +  return vec_add (x, y);
> +}
> +
> +vector unsigned char
> +test4 (vector bool char x,

[PATCH, rs6000] Fold vector addition built-ins in GIMPLE

2016-11-01 Thread Bill Schmidt
Hi,

As Jakub suggested in response to my *ahem* ornate patch for overloaded
function built-ins, a much better approach is to use the existing
machinery for overloading and then immediately fold the specific
functions during gimplification.  There is a target hook available for
this purpose that we have not previously used.  This patch demonstrates
this functionality by implementing the target hook and folding vector
addition built-ins within it.  Future patches will fold other such
operations, improving the optimization available for many vector
intrinsics.

Bootstrapped and tested on powerpc64le-unknown-linux-gnu with no
regressions.  Is this ok for trunk?

Thanks,
Bill


[gcc]

2016-11-01  Bill Schmidt  

* config/rs6000/rs6000.c (gimple-ssa.h): New #include.
(TARGET_GIMPLE_FOLD_BUILTIN): Define as
rs6000_gimple_fold_builtin.
(rs6000_gimple_fold_builtin): New function.  Add handling for
early expansion of vector addition builtins.


[gcc/testsuite]

2016-11-01  Bill Schmidt  

* gcc.target/powerpc/fold-vec-add-1.c: New.
* gcc.target/powerpc/fold-vec-add-2.c: New.
* gcc.target/powerpc/fold-vec-add-3.c: New.
* gcc.target/powerpc/fold-vec-add-4.c: New.
* gcc.target/powerpc/fold-vec-add-5.c: New.
* gcc.target/powerpc/fold-vec-add-6.c: New.
* gcc.target/powerpc/fold-vec-add-7.c: New.


Index: gcc/config/rs6000/rs6000.c
===
--- gcc/config/rs6000/rs6000.c  (revision 241624)
+++ gcc/config/rs6000/rs6000.c  (working copy)
@@ -56,6 +56,7 @@
 #include "sched-int.h"
 #include "gimplify.h"
 #include "gimple-iterator.h"
+#include "gimple-ssa.h"
 #include "gimple-walk.h"
 #include "intl.h"
 #include "params.h"
@@ -1632,6 +1633,8 @@ static const struct attribute_spec rs6000_attribut
 
 #undef TARGET_FOLD_BUILTIN
 #define TARGET_FOLD_BUILTIN rs6000_fold_builtin
+#undef TARGET_GIMPLE_FOLD_BUILTIN
+#define TARGET_GIMPLE_FOLD_BUILTIN rs6000_gimple_fold_builtin
 
 #undef TARGET_EXPAND_BUILTIN
 #define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
@@ -16337,6 +16340,46 @@ rs6000_fold_builtin (tree fndecl, int n_args ATTRI
 #endif
 }
 
+/* Fold a machine-dependent built-in in GIMPLE.  (For folding into
+   a constant, use rs6000_fold_builtin.)  */
+
+bool
+rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi)
+{
+  gimple *stmt = gsi_stmt (*gsi);
+  tree fndecl = gimple_call_fndecl (stmt);
+  gcc_checking_assert (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD);
+  enum rs6000_builtins fn_code
+= (enum rs6000_builtins) DECL_FUNCTION_CODE (fndecl);
+  tree arg0, arg1, lhs;
+
+  switch (fn_code)
+{
+/* Flavors of vec_add.  We deliberately don't expand
+   P8V_BUILTIN_VADDUQM as it gets lowered from V1TImode to
+   TImode, resulting in much poorer code generation.  */
+case ALTIVEC_BUILTIN_VADDUBM:
+case ALTIVEC_BUILTIN_VADDUHM:
+case ALTIVEC_BUILTIN_VADDUWM:
+case P8V_BUILTIN_VADDUDM:
+case ALTIVEC_BUILTIN_VADDFP:
+case VSX_BUILTIN_XVADDDP:
+  {
+   arg0 = gimple_call_arg (stmt, 0);
+   arg1 = gimple_call_arg (stmt, 1);
+   lhs = gimple_call_lhs (stmt);
+   gimple *g = gimple_build_assign (lhs, PLUS_EXPR, arg0, arg1);
+   gimple_set_location (g, gimple_location (stmt));
+   gsi_replace (gsi, g, true);
+   return true;
+  }
+default:
+  break;
+}
+
+  return false;
+}
+
 /* Expand an expression EXP that calls a built-in function,
with result going to TARGET if that's convenient
(and in mode MODE if that's convenient).
Index: gcc/testsuite/gcc.target/powerpc/fold-vec-add-1.c
===
--- gcc/testsuite/gcc.target/powerpc/fold-vec-add-1.c   (revision 0)
+++ gcc/testsuite/gcc.target/powerpc/fold-vec-add-1.c   (working copy)
@@ -0,0 +1,46 @@
+/* Verify that overloaded built-ins for vec_add with char
+   inputs produce the right results.  */
+
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_altivec_ok } */
+/* { dg-additional-options "-std=gnu11" } */
+
+#include 
+
+vector signed char
+test1 (vector bool char x, vector signed char y)
+{
+  return vec_add (x, y);
+}
+
+vector signed char
+test2 (vector signed char x, vector bool char y)
+{
+  return vec_add (x, y);
+}
+
+vector signed char
+test3 (vector signed char x, vector signed char y)
+{
+  return vec_add (x, y);
+}
+
+vector unsigned char
+test4 (vector bool char x, vector unsigned char y)
+{
+  return vec_add (x, y);
+}
+
+vector unsigned char
+test5 (vector unsigned char x, vector bool char y)
+{
+  return vec_add (x, y);
+}
+
+vector unsigned char
+test6 (vector unsigned char x, vector unsigned char y)
+{
+  return vec_add (x, y);
+}
+
+/* { dg-final { scan-assembler-times "vaddubm" 6 } } */
Index: gcc/testsuite/gcc.target/powerpc/fold-vec-add-2.c
===
--- gcc/testsuite/gcc.ta