[PATCH, rs6000] Disable gimple fold for float or double vec_minmax when fast-math is not set
HAO CHEN GUI
guihaoc@linux.ibm.com
Mon Nov 1 06:48:47 GMT 2021
Hi,
This patch disables gimple folding for VSX_BUILTIN_XVMINDP, VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMINFP and ALTIVEC_BUILTIN_VMAXFP when fast-math is not set. With the gimple folding is enabled, the four built-ins will be implemented by c-type instructions - xs[min|max]cdp on P9 and P10 if they can be converted to scalar comparisons. While they are implemented by xv[min|max][s|d]p on P8 and P7 as P8 and P7 don't have corresponding scalar comparison instructions. The patch binds these four built-ins to xv[min|max][s|d]p when fast-math is not set. The two new test cases illustrate it.
ALTIVEC_BUILTIN_VMINFP and ALTIVEC_BUILTIN_VMAXFP are not implemented by vminfp or vmaxfp.
rs6000-builtin.def:BU_ALTIVEC_2 (VMAXFP, "vmaxfp", CONST, smaxv4sf3)
rs6000-builtin.def:BU_ALTIVEC_2 (VMINFP, "vminfp", CONST, sminv4sf3)
Bootstrapped and tested on powerpc64le-linux with no regressions. Is this okay for trunk? Any recommendations? Thanks a lot.
ChangeLog
2021-11-01 Haochen Gui <guihaoc@linux.ibm.com>
gcc/
* config/rs6000/rs6000-call.c (rs6000_gimple_fold_builtin): Disable
gimple fold for VSX_BUILTIN_XVMINDP, ALTIVEC_BUILTIN_VMINFP,
VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMAXFP when fast-math is not
set.
gcc/testsuite/
* gcc.target/powerpc/vec-minmax-1.c: New test.
* gcc.target/powerpc/vec-minmax-2.c: Likewise.
patch.diff
diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c
new file mode 100644
index 00000000000..e238659c9be
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c
@@ -0,0 +1,52 @@
+/* { dg-require-effective-target powerpc_p9vector_ok } */
+/* { dg-options "-O2 -mdejagnu-cpu=power9" } */
+/* { dg-final { scan-assembler-times {\mxvmaxdp\M} 1 } } */
+/* { dg-final { scan-assembler-times {\mxvmaxsp\M} 1 } } */
+/* { dg-final { scan-assembler-times {\mxvmindp\M} 1 } } */
+/* { dg-final { scan-assembler-times {\mxvminsp\M} 1 } } */
+
+/* This test verifies that float or double vec_min/max are bound to
+ xv[min|max][d|s]p instructions when fast-math is not set. */
+
+
+#include <altivec.h>
+
+#ifdef _BIG_ENDIAN
+ const int PREF_D = 0;
+#else
+ const int PREF_D = 1;
+#endif
+
+double vmaxd (double a, double b)
+{
+ vector double va = vec_promote (a, PREF_D);
+ vector double vb = vec_promote (b, PREF_D);
+ return vec_extract (vec_max (va, vb), PREF_D);
+}
+
+double vmind (double a, double b)
+{
+ vector double va = vec_promote (a, PREF_D);
+ vector double vb = vec_promote (b, PREF_D);
+ return vec_extract (vec_min (va, vb), PREF_D);
+}
+
+#ifdef _BIG_ENDIAN
+ const int PREF_F = 0;
+#else
+ const int PREF_F = 3;
+#endif
+
+float vmaxf (float a, float b)
+{
+ vector float va = vec_promote (a, PREF_F);
+ vector float vb = vec_promote (b, PREF_F);
+ return vec_extract (vec_max (va, vb), PREF_F);
+}
+
+float vminf (float a, float b)
+{
+ vector float va = vec_promote (a, PREF_F);
+ vector float vb = vec_promote (b, PREF_F);
+ return vec_extract (vec_min (va, vb), PREF_F);
+}
diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c
new file mode 100644
index 00000000000..149275d8709
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c
@@ -0,0 +1,50 @@
+/* { dg-require-effective-target powerpc_p9vector_ok } */
+/* { dg-options "-O2 -mdejagnu-cpu=power9 -ffast-math" } */
+/* { dg-final { scan-assembler-times {\mxsmaxcdp\M} 2 } } */
+/* { dg-final { scan-assembler-times {\mxsmincdp\M} 2 } } */
+
+/* This test verifies that float or double vec_min/max can be converted
+ to scalar comparison when fast-math is set. */
+
+
+#include <altivec.h>
+
+#ifdef _BIG_ENDIAN
+ const int PREF_D = 0;
+#else
+ const int PREF_D = 1;
+#endif
+
+double vmaxd (double a, double b)
+{
+ vector double va = vec_promote (a, PREF_D);
+ vector double vb = vec_promote (b, PREF_D);
+ return vec_extract (vec_max (va, vb), PREF_D);
+}
+
+double vmind (double a, double b)
+{
+ vector double va = vec_promote (a, PREF_D);
+ vector double vb = vec_promote (b, PREF_D);
+ return vec_extract (vec_min (va, vb), PREF_D);
+}
+
+#ifdef _BIG_ENDIAN
+ const int PREF_F = 0;
+#else
+ const int PREF_F = 3;
+#endif
+
+float vmaxf (float a, float b)
+{
+ vector float va = vec_promote (a, PREF_F);
+ vector float vb = vec_promote (b, PREF_F);
+ return vec_extract (vec_max (va, vb), PREF_F);
+}
+
+float vminf (float a, float b)
+{
+ vector float va = vec_promote (a, PREF_F);
+ vector float vb = vec_promote (b, PREF_F);
+ return vec_extract (vec_min (va, vb), PREF_F);
+}
-------------- next part --------------
2021-11-01 Haochen Gui <guihaoc@linux.ibm.com>
gcc/
* config/rs6000/rs6000-call.c (rs6000_gimple_fold_builtin): Disable
gimple fold for VSX_BUILTIN_XVMINDP, ALTIVEC_BUILTIN_VMINFP,
VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMAXFP when fast-math is not
set.
gcc/testsuite/
* gcc.target/powerpc/vec-minmax-1.c: New test.
* gcc.target/powerpc/vec-minmax-2.c: Likewise.
-------------- next part --------------
diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c
new file mode 100644
index 00000000000..e238659c9be
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c
@@ -0,0 +1,52 @@
+/* { dg-require-effective-target powerpc_p9vector_ok } */
+/* { dg-options "-O2 -mdejagnu-cpu=power9" } */
+/* { dg-final { scan-assembler-times {\mxvmaxdp\M} 1 } } */
+/* { dg-final { scan-assembler-times {\mxvmaxsp\M} 1 } } */
+/* { dg-final { scan-assembler-times {\mxvmindp\M} 1 } } */
+/* { dg-final { scan-assembler-times {\mxvminsp\M} 1 } } */
+
+/* This test verifies that float or double vec_min/max are bound to
+ xv[min|max][d|s]p instructions when fast-math is not set. */
+
+
+#include <altivec.h>
+
+#ifdef _BIG_ENDIAN
+ const int PREF_D = 0;
+#else
+ const int PREF_D = 1;
+#endif
+
+double vmaxd (double a, double b)
+{
+ vector double va = vec_promote (a, PREF_D);
+ vector double vb = vec_promote (b, PREF_D);
+ return vec_extract (vec_max (va, vb), PREF_D);
+}
+
+double vmind (double a, double b)
+{
+ vector double va = vec_promote (a, PREF_D);
+ vector double vb = vec_promote (b, PREF_D);
+ return vec_extract (vec_min (va, vb), PREF_D);
+}
+
+#ifdef _BIG_ENDIAN
+ const int PREF_F = 0;
+#else
+ const int PREF_F = 3;
+#endif
+
+float vmaxf (float a, float b)
+{
+ vector float va = vec_promote (a, PREF_F);
+ vector float vb = vec_promote (b, PREF_F);
+ return vec_extract (vec_max (va, vb), PREF_F);
+}
+
+float vminf (float a, float b)
+{
+ vector float va = vec_promote (a, PREF_F);
+ vector float vb = vec_promote (b, PREF_F);
+ return vec_extract (vec_min (va, vb), PREF_F);
+}
diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c
new file mode 100644
index 00000000000..149275d8709
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c
@@ -0,0 +1,50 @@
+/* { dg-require-effective-target powerpc_p9vector_ok } */
+/* { dg-options "-O2 -mdejagnu-cpu=power9 -ffast-math" } */
+/* { dg-final { scan-assembler-times {\mxsmaxcdp\M} 2 } } */
+/* { dg-final { scan-assembler-times {\mxsmincdp\M} 2 } } */
+
+/* This test verifies that float or double vec_min/max can be converted
+ to scalar comparison when fast-math is set. */
+
+
+#include <altivec.h>
+
+#ifdef _BIG_ENDIAN
+ const int PREF_D = 0;
+#else
+ const int PREF_D = 1;
+#endif
+
+double vmaxd (double a, double b)
+{
+ vector double va = vec_promote (a, PREF_D);
+ vector double vb = vec_promote (b, PREF_D);
+ return vec_extract (vec_max (va, vb), PREF_D);
+}
+
+double vmind (double a, double b)
+{
+ vector double va = vec_promote (a, PREF_D);
+ vector double vb = vec_promote (b, PREF_D);
+ return vec_extract (vec_min (va, vb), PREF_D);
+}
+
+#ifdef _BIG_ENDIAN
+ const int PREF_F = 0;
+#else
+ const int PREF_F = 3;
+#endif
+
+float vmaxf (float a, float b)
+{
+ vector float va = vec_promote (a, PREF_F);
+ vector float vb = vec_promote (b, PREF_F);
+ return vec_extract (vec_max (va, vb), PREF_F);
+}
+
+float vminf (float a, float b)
+{
+ vector float va = vec_promote (a, PREF_F);
+ vector float vb = vec_promote (b, PREF_F);
+ return vec_extract (vec_min (va, vb), PREF_F);
+}
More information about the Gcc-patches
mailing list