GCC should support inline code generation for hypot functions, under appropriate fast-math conditions. glibc's bits/mathinline.h, for 32-bit non-SSE fast-math x86 only, has: /* The argument range of the inline version of hypotl is slightly reduced. */ __inline_mathcodeNP2 (hypot, __x, __y, return __libc_sqrtl (__x * __x + __y * __y)) We're moving away from such inlines in glibc, preferring to leave it to the compiler to inline standard functions under appropriate conditions. Although this is filed as a target issue, inlining hypot functions (given -funsafe-math-optimizations, as it may change results, and -ffinite-math-only, as it won't be correct for Inf, NaN arguments) is actually reasonably generic. There are separate cases for when it's possible to do the * + sqrt operations on a wider (hardware) type, so avoiding reducing the argument range, and when a wider hardware type is unavailable or inappropriate to use, in which case the argument range would be reduced by inlining (although that glibc inline still does it for long double).
Created attachment 45224 [details] Proposed patch Patch that implements hypotf and hypot using x87 XFmode arithmetic.
Author: uros Date: Fri Dec 14 17:04:48 2018 New Revision: 267137 URL: https://gcc.gnu.org/viewcvs?rev=267137&root=gcc&view=rev Log: PR target/88474 * internal-fn.def (HYPOT): New. * optabs.def (hypot_optab): New. * config/i386/i386.md (hypot<mode>3): New expander. Modified: trunk/gcc/ChangeLog trunk/gcc/config/i386/i386.md trunk/gcc/internal-fn.def trunk/gcc/optabs.def
Implemented for gcc-9.
It isn't implemented for any other targets yet. When I use __builtin_hypot with -ffast-math (I tried on powerpc64-linux) I get a call to __hypot_finite, instead of just three machine instructions, like e.g. fmul 2,2,2 fmadd 1,1,1,2 fsqrt 1,1 which is what you get for double hypot(double x, double y) { return __builtin_sqrt(x*x + y*y); } Reopened. (Or do you want this PR to be just for x87? If so, why?)
GCC 9.1 has been released.
GCC 9.2 has been released.
GCC 9.3.0 has been released, adjusting target milestone.
GCC 9.4 is being released, retargeting bugs to GCC 9.5.