Simplify (trunc)copysign((extend)a, (extend)b) to .COPYSIGN (a,b).

a and b are same type as the truncation type and has less precision
than extend type.

gcc/ChangeLog:

	PR target/102464
	* match.pd: simplify (trunc)copysign((extend)a, (extend)b) to
	.COPYSIGN (a,b) when a and b are same type as the truncation
	type and has less precision than extend type.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr102464-copysign-1.c: New test.
This commit is contained in:
liuhongt 2021-11-03 16:07:34 +08:00
parent d0d428c4ce
commit 22ce7382fc
2 changed files with 94 additions and 0 deletions

View File

@ -6169,6 +6169,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& direct_internal_fn_supported_p (as_internal_fn (tos),
type, OPTIMIZE_FOR_BOTH))
(tos @0))))
/* Simplify (trunc)copysign ((extend)x, (extend)y) to copysignf (x, y),
x,y is float value, similar for _Float16/double. */
(for copysigns (COPYSIGN_ALL)
(simplify
(convert (copysigns (convert@2 @0) (convert @1)))
(if (optimize
&& types_match (type, TREE_TYPE (@0))
&& types_match (type, TREE_TYPE (@1))
&& TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@2))
&& direct_internal_fn_supported_p (IFN_COPYSIGN,
type, OPTIMIZE_FOR_BOTH))
(IFN_COPYSIGN @0 @1))))
#endif
(for froms (XFLOORL XCEILL XROUNDL XRINTL)

View File

@ -0,0 +1,80 @@
/* PR target/102464. */
/* { dg-do compile } */
/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ftree-vectorize -mfpmath=sse -fdump-tree-optimized" } */
#include<math.h>
void foo1 (_Float16* __restrict a, _Float16* b, _Float16* c)
{
for (int i = 0; i != 8; i++)
a[i] = copysignf (b[i], c[i]);
}
void foo2 (_Float16* __restrict a, _Float16* b, _Float16* c)
{
for (int i = 0; i != 8; i++)
a[i] = copysign (b[i], c[i]);
}
void foo3 (_Float16* __restrict a, _Float16* b, _Float16* c)
{
for (int i = 0; i != 8; i++)
a[i] = copysignl (b[i], c[i]);
}
void foo4 (float* __restrict a, float* b, float* c)
{
for (int i = 0; i != 4; i++)
a[i] = copysign (b[i], c[i]);
}
void foo5 (float* __restrict a, float* b, float* c)
{
for (int i = 0; i != 4; i++)
a[i] = copysignl (b[i], c[i]);
}
void foo6 (double* __restrict a, double* b, double* c)
{
for (int i = 0; i != 4; i++)
a[i] = copysignl (b[i], c[i]);
}
void foo7 (_Float16* __restrict a, _Float16* b, _Float16* c)
{
a[0] = copysignf (b[0], c[0]);
}
void foo8 (_Float16* __restrict a, _Float16* b, _Float16* c)
{
a[0] = copysign (b[0], c[0]);
}
void foo9 (_Float16* __restrict a, _Float16* b, _Float16* c)
{
a[0] = copysignl (b[0], c[0]);
}
void foo10 (float* __restrict a, float* b, float* c)
{
a[0] = copysign (b[0], c[0]);
}
void foo11 (float* __restrict a, float* b, float* c)
{
a[0] = copysignl (b[0], c[0]);
}
void foo12 (double* __restrict a, double* b, double* c)
{
a[0] = copysignl (b[0], c[0]);
}
/* { dg-final { scan-assembler-not "vcvtsh2s\[sd\]" } } */
/* { dg-final { scan-assembler-not "vcvtss2sd" } } */
/* { dg-final { scan-assembler-not "fld" } } */
/* { dg-final { scan-assembler-not "vcvtph2p\[sd\]" } } */
/* { dg-final { scan-assembler-not "vcvtps2pd" } } */
/* { dg-final { scan-assembler-not "extendhfxf" } } */
/* { dg-final { scan-assembler-not "\\\{1to8\\\}" } } */
/* { dg-final { scan-tree-dump-times "\.COPYSIGN" 12 "optimized" } } */
/* { dg-final { scan-assembler-times "vpternlog" 12 } } */