public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] match.pd: Only merge truncation with conversion for -fno-signed-zeros
@ 2024-03-13 14:38 Joe Ramsay
  2024-03-14  7:38 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Joe Ramsay @ 2024-03-13 14:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: Joe Ramsay

This optimisation does not honour signed zeros, so should not be
enabled except with -fno-signed-zeros.

OK for master? I do not have commit rights for GCC, so if the patch
is fine would someone be able to commit for me? The bug is present
in all GCC versions from 12.1.0 onwards - is it possible to backport
this?

Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.

Thanks,
Joe

gcc/ChangeLog:

	* match.pd: Fix truncation pattern for -fno-signed-zeroes

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/no_merge_trunc_signed_zero.c: New test.
---
 gcc/match.pd                                  |  2 +-
 .../aarch64/no_merge_trunc_signed_zero.c      | 24 +++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/no_merge_trunc_signed_zero.c

diff --git a/gcc/match.pd b/gcc/match.pd
index 9ce313323a3..45c34c810cf 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4857,7 +4857,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 #if GIMPLE
 (simplify
    (float (fix_trunc @0))
-   (if (!flag_trapping_math
+   (if (!flag_trapping_math && !HONOR_SIGNED_ZEROS(type)
 	&& types_match (type, TREE_TYPE (@0))
 	&& direct_internal_fn_supported_p (IFN_TRUNC, type,
 					  OPTIMIZE_FOR_BOTH))
diff --git a/gcc/testsuite/gcc.target/aarch64/no_merge_trunc_signed_zero.c b/gcc/testsuite/gcc.target/aarch64/no_merge_trunc_signed_zero.c
new file mode 100644
index 00000000000..b2c93e55567
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/no_merge_trunc_signed_zero.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-trapping-math -fsigned-zeros" } */
+
+#include <math.h>
+
+float
+f1 (float x)
+{
+  return (int) rintf(x);
+}
+
+double
+f2 (double x)
+{
+  return (long) rint(x);
+}
+
+/* { dg-final { scan-assembler "frintx\\ts\[0-9\]+, s\[0-9\]+" } } */
+/* { dg-final { scan-assembler "cvtzs\\ts\[0-9\]+, s\[0-9\]+" } } */
+/* { dg-final { scan-assembler "scvtf\\ts\[0-9\]+, s\[0-9\]+" } } */
+/* { dg-final { scan-assembler "frintx\\td\[0-9\]+, d\[0-9\]+" } } */
+/* { dg-final { scan-assembler "cvtzs\\td\[0-9\]+, d\[0-9\]+" } } */
+/* { dg-final { scan-assembler "scvtf\\td\[0-9\]+, d\[0-9\]+" } } */
+
-- 
2.27.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] match.pd: Only merge truncation with conversion for -fno-signed-zeros
  2024-03-13 14:38 [PATCH] match.pd: Only merge truncation with conversion for -fno-signed-zeros Joe Ramsay
@ 2024-03-14  7:38 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2024-03-14  7:38 UTC (permalink / raw)
  To: Joe Ramsay; +Cc: gcc-patches

On Wed, Mar 13, 2024 at 3:39 PM Joe Ramsay <Joe.Ramsay@arm.com> wrote:
>
> This optimisation does not honour signed zeros, so should not be
> enabled except with -fno-signed-zeros.
>
> OK for master? I do not have commit rights for GCC, so if the patch
> is fine would someone be able to commit for me? The bug is present
> in all GCC versions from 12.1.0 onwards - is it possible to backport
> this?
>
> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
>
> Thanks,
> Joe
>
> gcc/ChangeLog:
>
>         * match.pd: Fix truncation pattern for -fno-signed-zeroes
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/aarch64/no_merge_trunc_signed_zero.c: New test.
> ---
>  gcc/match.pd                                  |  2 +-
>  .../aarch64/no_merge_trunc_signed_zero.c      | 24 +++++++++++++++++++
>  2 files changed, 25 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/aarch64/no_merge_trunc_signed_zero.c
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 9ce313323a3..45c34c810cf 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -4857,7 +4857,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>  #if GIMPLE
>  (simplify
>     (float (fix_trunc @0))
> -   (if (!flag_trapping_math
> +   (if (!flag_trapping_math && !HONOR_SIGNED_ZEROS(type)

put the && to the next line and add a space before (type)

OK with that change.

Richard.

>         && types_match (type, TREE_TYPE (@0))
>         && direct_internal_fn_supported_p (IFN_TRUNC, type,
>                                           OPTIMIZE_FOR_BOTH))
> diff --git a/gcc/testsuite/gcc.target/aarch64/no_merge_trunc_signed_zero.c b/gcc/testsuite/gcc.target/aarch64/no_merge_trunc_signed_zero.c
> new file mode 100644
> index 00000000000..b2c93e55567
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/aarch64/no_merge_trunc_signed_zero.c
> @@ -0,0 +1,24 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fno-trapping-math -fsigned-zeros" } */
> +
> +#include <math.h>
> +
> +float
> +f1 (float x)
> +{
> +  return (int) rintf(x);
> +}
> +
> +double
> +f2 (double x)
> +{
> +  return (long) rint(x);
> +}
> +
> +/* { dg-final { scan-assembler "frintx\\ts\[0-9\]+, s\[0-9\]+" } } */
> +/* { dg-final { scan-assembler "cvtzs\\ts\[0-9\]+, s\[0-9\]+" } } */
> +/* { dg-final { scan-assembler "scvtf\\ts\[0-9\]+, s\[0-9\]+" } } */
> +/* { dg-final { scan-assembler "frintx\\td\[0-9\]+, d\[0-9\]+" } } */
> +/* { dg-final { scan-assembler "cvtzs\\td\[0-9\]+, d\[0-9\]+" } } */
> +/* { dg-final { scan-assembler "scvtf\\td\[0-9\]+, d\[0-9\]+" } } */
> +
> --
> 2.27.0
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-14  7:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-13 14:38 [PATCH] match.pd: Only merge truncation with conversion for -fno-signed-zeros Joe Ramsay
2024-03-14  7:38 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).