Similar for sqrt/sqrtl.
gcc/ChangeLog:
PR target/102464
* match.pd: Simplify (_Float16) sqrtf((float) a) to .SQRT(a)
when direct_internal_fn_supported_p, similar for sqrt/sqrtl.
gcc/testsuite/ChangeLog:
PR target/102464
* gcc.target/i386/pr102464-sqrtph.c: New test.
* gcc.target/i386/pr102464-sqrtsh.c: New test.
BUILT_IN_ROUNDEVENL BUILT_IN_ROUNDEVEN BUILT_IN_ROUNDEVENF
BUILT_IN_ROUNDL BUILT_IN_ROUND BUILT_IN_ROUNDF
BUILT_IN_NEARBYINTL BUILT_IN_NEARBYINT BUILT_IN_NEARBYINTF
- BUILT_IN_RINTL BUILT_IN_RINT BUILT_IN_RINTF)
+ BUILT_IN_RINTL BUILT_IN_RINT BUILT_IN_RINTF
+ BUILT_IN_SQRTL BUILT_IN_SQRT BUILT_IN_SQRTF)
tos (IFN_TRUNC IFN_TRUNC IFN_TRUNC
IFN_FLOOR IFN_FLOOR IFN_FLOOR
IFN_CEIL IFN_CEIL IFN_CEIL
IFN_ROUNDEVEN IFN_ROUNDEVEN IFN_ROUNDEVEN
IFN_ROUND IFN_ROUND IFN_ROUND
IFN_NEARBYINT IFN_NEARBYINT IFN_NEARBYINT
- IFN_RINT IFN_RINT IFN_RINT)
+ IFN_RINT IFN_RINT IFN_RINT
+ IFN_SQRT IFN_SQRT IFN_SQRT)
/* (_Float16) round ((doube) x) -> __built_in_roundf16 (x), etc.,
if x is a _Float16. */
(simplify
--- /dev/null
+/* PR target/102464. */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ffast-math -ftree-vectorize" } */
+
+#include<math.h>
+void foo1 (_Float16* __restrict a, _Float16* b)
+{
+ for (int i = 0; i != 8; i++)
+ a[i] = sqrtf (b[i]);
+}
+
+void foo2 (_Float16* __restrict a, _Float16* b)
+{
+ for (int i = 0; i != 8; i++)
+ a[i] = sqrt (b[i]);
+}
+
+void foo3 (_Float16* __restrict a, _Float16* b)
+{
+ for (int i = 0; i != 8; i++)
+ a[i] = sqrtl (b[i]);
+}
+
+/* { dg-final { scan-assembler-not "vcvtsh2s\[sd\]" } } */
+/* { dg-final { scan-assembler-not "vcvtph2p\[sd\]" } } */
+/* { dg-final { scan-assembler-not "extendhfxf" } } */
+/* { dg-final { scan-assembler-times "vsqrtph\[^\n\r\]*xmm\[0-9\]" 3 } } */
--- /dev/null
+/* PR target/102464. */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512fp16 -ffast-math" } */
+
+#include<math.h>
+_Float16 foo1 (_Float16 a)
+{
+ return sqrtf (a);
+}
+
+_Float16 foo2 (_Float16 a)
+{
+ return sqrt (a);
+}
+
+_Float16 foo3 (_Float16 a)
+{
+ return sqrtl (a);
+}
+
+/* { dg-final { scan-assembler-not "vcvtsh2s\[sd\]" } } */
+/* { dg-final { scan-assembler-not "extendhfxf" } } */
+/* { dg-final { scan-assembler-times "vsqrtsh\[^\n\r\]*xmm\[0-9\]" 3 } } */