Attached patch inlines calls to hypotf and hypot using x87 XFmode arithmetic.
2018-12-14 Uros Bizjak <[email protected]>
PR target/88474
* internal-fn.def (HYPOT): New.
* optabs.def (hypot_optab): New.
* config/i386/i386.md (hypot<mode>3): New expander.
Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.
There are a couple of one-liners in middle-end part, so patch also
needs middle-end approval.
OK for mainline?
Uros.
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 5e46bdcdd37..537b90c3b4b 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -15048,6 +15048,32 @@
}
})
+(define_expand "hypot<mode>3"
+ [(use (match_operand:MODEF 0 "register_operand"))
+ (use (match_operand:MODEF 1 "general_operand"))
+ (use (match_operand:MODEF 2 "general_operand"))]
+ "TARGET_USE_FANCY_MATH_387
+ && (!(SSE_FLOAT_MODE_P (<MODE>mode) && TARGET_SSE_MATH)
+ || TARGET_MIX_SSE_I387)
+ && flag_finite_math_only
+ && flag_unsafe_math_optimizations"
+{
+ rtx op0 = gen_reg_rtx (XFmode);
+ rtx op1 = gen_reg_rtx (XFmode);
+ rtx op2 = gen_reg_rtx (XFmode);
+
+ emit_insn (gen_extend<mode>xf2 (op2, operands[2]));
+ emit_insn (gen_extend<mode>xf2 (op1, operands[1]));
+
+ emit_insn (gen_mulxf3 (op1, op1, op1));
+ emit_insn (gen_mulxf3 (op2, op2, op2));
+ emit_insn (gen_addxf3 (op0, op2, op1));
+ emit_insn (gen_sqrtxf2 (op0, op0));
+
+ emit_insn (gen_truncxf<mode>2 (operands[0], op0));
+ DONE;
+})
+
(define_insn "x86_fnstsw_1"
[(set (match_operand:HI 0 "register_operand" "=a")
(unspec:HI [(reg:CCFP FPSR_REG)] UNSPEC_FNSTSW))]
diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def
index cda314e1121..593eead4ef1 100644
--- a/gcc/internal-fn.def
+++ b/gcc/internal-fn.def
@@ -230,6 +230,7 @@ DEF_INTERNAL_FLT_FLOATN_FN (TRUNC, ECF_CONST, btrunc, unary)
DEF_INTERNAL_FLT_FN (ATAN2, ECF_CONST, atan2, binary)
DEF_INTERNAL_FLT_FLOATN_FN (COPYSIGN, ECF_CONST, copysign, binary)
DEF_INTERNAL_FLT_FN (FMOD, ECF_CONST, fmod, binary)
+DEF_INTERNAL_FLT_FN (HYPOT, ECF_CONST, hypot, binary)
DEF_INTERNAL_FLT_FN (POW, ECF_CONST, pow, binary)
DEF_INTERNAL_FLT_FN (REMAINDER, ECF_CONST, remainder, binary)
DEF_INTERNAL_FLT_FN (SCALB, ECF_CONST, scalb, binary)
diff --git a/gcc/optabs.def b/gcc/optabs.def
index 5a67f5eed5e..2d039e7682b 100644
--- a/gcc/optabs.def
+++ b/gcc/optabs.def
@@ -284,6 +284,7 @@ OPTAB_D (exp2_optab, "exp2$a2")
OPTAB_D (exp_optab, "exp$a2")
OPTAB_D (expm1_optab, "expm1$a2")
OPTAB_D (fmod_optab, "fmod$a3")
+OPTAB_D (hypot_optab, "hypot$a3")
OPTAB_D (ilogb_optab, "ilogb$a2")
OPTAB_D (isinf_optab, "isinf$a2")
OPTAB_D (ldexp_optab, "ldexp$a3")