gimple_set_location (g, gimple_location (stmt));
gsi_replace (gsi, g, true);
return true;
+ /* fold into MIN_EXPR when fast-math is set. */
+ case RS6000_BIF_XSMINDP:
/* flavors of vec_min. */
case RS6000_BIF_XVMINDP:
case RS6000_BIF_XVMINSP:
gimple_set_location (g, gimple_location (stmt));
gsi_replace (gsi, g, true);
return true;
+ /* fold into MAX_EXPR when fast-math is set. */
+ case RS6000_BIF_XSMAXDP:
/* flavors of vec_max. */
case RS6000_BIF_XVMAXDP:
case RS6000_BIF_XVMAXSP:
XSCVSPDP vsx_xscvspdp {}
const double __builtin_vsx_xsmaxdp (double, double);
- XSMAXDP smaxdf3 {}
+ XSMAXDP fmaxdf3 {}
const double __builtin_vsx_xsmindp (double, double);
- XSMINDP smindf3 {}
+ XSMINDP fmindf3 {}
const double __builtin_vsx_xsrdpi (double);
XSRDPI vsx_xsrdpi {}
UNSPEC_HASHCHK
UNSPEC_XXSPLTIDP_CONST
UNSPEC_XXSPLTIW_CONST
+ UNSPEC_FMAX
+ UNSPEC_FMIN
])
;;
DONE;
})
+
+(define_int_iterator FMINMAX [UNSPEC_FMAX UNSPEC_FMIN])
+
+(define_int_attr minmax_op [(UNSPEC_FMAX "max")
+ (UNSPEC_FMIN "min")])
+
+(define_insn "f<minmax_op><mode>3"
+ [(set (match_operand:SFDF 0 "vsx_register_operand" "=wa")
+ (unspec:SFDF [(match_operand:SFDF 1 "vsx_register_operand" "wa")
+ (match_operand:SFDF 2 "vsx_register_operand" "wa")]
+ FMINMAX))]
+ "TARGET_VSX && !flag_finite_math_only"
+ "xs<minmax_op>dp %x0,%x1,%x2"
+ [(set_attr "type" "fp")]
+)
+
(define_expand "mov<mode>cc"
[(set (match_operand:GPR 0 "gpc_reg_operand")
(if_then_else:GPR (match_operand 1 "comparison_operator")
--- /dev/null
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-O2 -mvsx" } */
+/* { dg-final { scan-assembler-times {\mxsmaxdp\M} 3 } } */
+/* { dg-final { scan-assembler-times {\mxsmindp\M} 3 } } */
+
+/* Verify that GCC generates expected min/max hw insns instead of fmin/fmax
+ calls. */
+#include "pr103605.h"
--- /dev/null
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-O2 -mvsx -ffast-math" } */
+/* { dg-final { scan-assembler-times {\mxsmaxcdp\M} 3 { target has_arch_pwr9 } } } */
+/* { dg-final { scan-assembler-times {\mxsmincdp\M} 3 { target has_arch_pwr9 } } } */
+/* { dg-final { scan-assembler-times {\mxsmaxdp\M} 3 { target { ! has_arch_pwr9 } } } } */
+/* { dg-final { scan-assembler-times {\mxsmindp\M} 3 { target { ! has_arch_pwr9 } } } } */
+
+/* Verify that GCC generates expected min/max hw insns instead of fmin/fmax
+ calls. */
+#include "pr103605.h"
--- /dev/null
+#include <math.h>
+
+double test1 (double d0, double d1)
+{
+ return fmin (d0, d1);
+}
+
+float test2 (float d0, float d1)
+{
+ return fmin (d0, d1);
+}
+
+double test3 (double d0, double d1)
+{
+ return fmax (d0, d1);
+}
+
+float test4 (float d0, float d1)
+{
+ return fmax (d0, d1);
+}
+
+double test5 (double d0, double d1)
+{
+ return __builtin_vsx_xsmindp (d0, d1);
+}
+
+double test6 (double d0, double d1)
+{
+ return __builtin_vsx_xsmaxdp (d0, d1);
+}