* [PATCH v2] Only allow (int)trunc(x) to (int)x simplification with -ffp-int-builtin-inexact [PR107723]
@ 2023-11-24 9:09 Xi Ruoyao
2023-12-01 5:44 ` Ping: " Xi Ruoyao
0 siblings, 1 reply; 4+ messages in thread
From: Xi Ruoyao @ 2023-11-24 9:09 UTC (permalink / raw)
To: gcc-patches; +Cc: Joseph Myers, Richard Biener, Xi Ruoyao
With -fno-fp-int-builtin-inexact, trunc is not allowed to raise
FE_INEXACT and it should produce an integral result (if the input is not
NaN or Inf). Thus FE_INEXACT should not be raised.
But (int)x may raise FE_INEXACT when x is a non-integer, non-NaN, and
non-Inf value. C23 recommends to do so in a footnote.
Thus we should not simplify (int)trunc(x) to (int)x if
-fno-fp-int-builtin-inexact is in-effect.
gcc/ChangeLog:
PR middle-end/107723
* convert.cc (convert_to_integer_1) [case BUILT_IN_TRUNC]: Break
early if !flag_fp_int_builtin_inexact and flag_trapping_math.
gcc/testsuite/ChangeLog:
PR middle-end/107723
* gcc.dg/torture/builtin-fp-int-inexact-trunc.c: New test.
---
Change from v1: add flag_trapping_math into the condition.
Bootstrapped and regtested on x86_64-linux-gnu. Ok for trunk?
gcc/convert.cc | 3 ++-
.../gcc.dg/torture/builtin-fp-int-inexact-trunc.c | 12 ++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-trunc.c
diff --git a/gcc/convert.cc b/gcc/convert.cc
index 46c8bcb31f8..f214b750188 100644
--- a/gcc/convert.cc
+++ b/gcc/convert.cc
@@ -591,7 +591,8 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
CASE_FLT_FN (BUILT_IN_TRUNC):
CASE_FLT_FN_FLOATN_NX (BUILT_IN_TRUNC):
if (call_expr_nargs (s_expr) != 1
- || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (CALL_EXPR_ARG (s_expr, 0))))
+ || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (CALL_EXPR_ARG (s_expr, 0)))
+ || (!flag_fp_int_builtin_inexact && flag_trapping_math))
break;
return convert_to_integer_1 (type, CALL_EXPR_ARG (s_expr, 0),
dofold);
diff --git a/gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-trunc.c b/gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-trunc.c
new file mode 100644
index 00000000000..09731183621
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-trunc.c
@@ -0,0 +1,12 @@
+/* Test -fno-fp-int-builtin-inexact. */
+/* { dg-do compile } */
+/* { dg-options "-fno-fp-int-builtin-inexact -fdump-tree-original" } */
+
+long
+x (double y)
+{
+ return __builtin_trunc (y);
+}
+
+/* Optimization should not discard the __builtin_trunc call. */
+/* { dg-final { scan-tree-dump "__builtin_trunc" "original" } } */
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Ping: [PATCH v2] Only allow (int)trunc(x) to (int)x simplification with -ffp-int-builtin-inexact [PR107723]
2023-11-24 9:09 [PATCH v2] Only allow (int)trunc(x) to (int)x simplification with -ffp-int-builtin-inexact [PR107723] Xi Ruoyao
@ 2023-12-01 5:44 ` Xi Ruoyao
2023-12-11 6:39 ` PING^2: " Xi Ruoyao
0 siblings, 1 reply; 4+ messages in thread
From: Xi Ruoyao @ 2023-12-01 5:44 UTC (permalink / raw)
To: gcc-patches; +Cc: Joseph Myers, Richard Biener
Ping.
On Fri, 2023-11-24 at 17:09 +0800, Xi Ruoyao wrote:
> With -fno-fp-int-builtin-inexact, trunc is not allowed to raise
> FE_INEXACT and it should produce an integral result (if the input is not
> NaN or Inf). Thus FE_INEXACT should not be raised.
>
> But (int)x may raise FE_INEXACT when x is a non-integer, non-NaN, and
> non-Inf value. C23 recommends to do so in a footnote.
>
> Thus we should not simplify (int)trunc(x) to (int)x if
> -fno-fp-int-builtin-inexact is in-effect.
>
> gcc/ChangeLog:
>
> PR middle-end/107723
> * convert.cc (convert_to_integer_1) [case BUILT_IN_TRUNC]: Break
> early if !flag_fp_int_builtin_inexact and flag_trapping_math.
>
> gcc/testsuite/ChangeLog:
>
> PR middle-end/107723
> * gcc.dg/torture/builtin-fp-int-inexact-trunc.c: New test.
> ---
>
> Change from v1: add flag_trapping_math into the condition.
>
> Bootstrapped and regtested on x86_64-linux-gnu. Ok for trunk?
>
> gcc/convert.cc | 3 ++-
> .../gcc.dg/torture/builtin-fp-int-inexact-trunc.c | 12 ++++++++++++
> 2 files changed, 14 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-trunc.c
>
> diff --git a/gcc/convert.cc b/gcc/convert.cc
> index 46c8bcb31f8..f214b750188 100644
> --- a/gcc/convert.cc
> +++ b/gcc/convert.cc
> @@ -591,7 +591,8 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
> CASE_FLT_FN (BUILT_IN_TRUNC):
> CASE_FLT_FN_FLOATN_NX (BUILT_IN_TRUNC):
> if (call_expr_nargs (s_expr) != 1
> - || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (CALL_EXPR_ARG (s_expr, 0))))
> + || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (CALL_EXPR_ARG (s_expr, 0)))
> + || (!flag_fp_int_builtin_inexact && flag_trapping_math))
> break;
> return convert_to_integer_1 (type, CALL_EXPR_ARG (s_expr, 0),
> dofold);
> diff --git a/gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-trunc.c b/gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-trunc.c
> new file mode 100644
> index 00000000000..09731183621
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-trunc.c
> @@ -0,0 +1,12 @@
> +/* Test -fno-fp-int-builtin-inexact. */
> +/* { dg-do compile } */
> +/* { dg-options "-fno-fp-int-builtin-inexact -fdump-tree-original" } */
> +
> +long
> +x (double y)
> +{
> + return __builtin_trunc (y);
> +}
> +
> +/* Optimization should not discard the __builtin_trunc call. */
> +/* { dg-final { scan-tree-dump "__builtin_trunc" "original" } } */
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 4+ messages in thread
* PING^2: [PATCH v2] Only allow (int)trunc(x) to (int)x simplification with -ffp-int-builtin-inexact [PR107723]
2023-12-01 5:44 ` Ping: " Xi Ruoyao
@ 2023-12-11 6:39 ` Xi Ruoyao
2023-12-11 8:07 ` Richard Biener
0 siblings, 1 reply; 4+ messages in thread
From: Xi Ruoyao @ 2023-12-11 6:39 UTC (permalink / raw)
To: gcc-patches; +Cc: Joseph Myers, Richard Biener
Ping again.
On Fri, 2023-12-01 at 13:44 +0800, Xi Ruoyao wrote:
> Ping.
>
> On Fri, 2023-11-24 at 17:09 +0800, Xi Ruoyao wrote:
> > With -fno-fp-int-builtin-inexact, trunc is not allowed to raise
> > FE_INEXACT and it should produce an integral result (if the input is not
> > NaN or Inf). Thus FE_INEXACT should not be raised.
> >
> > But (int)x may raise FE_INEXACT when x is a non-integer, non-NaN, and
> > non-Inf value. C23 recommends to do so in a footnote.
> >
> > Thus we should not simplify (int)trunc(x) to (int)x if
> > -fno-fp-int-builtin-inexact is in-effect.
> >
> > gcc/ChangeLog:
> >
> > PR middle-end/107723
> > * convert.cc (convert_to_integer_1) [case BUILT_IN_TRUNC]: Break
> > early if !flag_fp_int_builtin_inexact and flag_trapping_math.
> >
> > gcc/testsuite/ChangeLog:
> >
> > PR middle-end/107723
> > * gcc.dg/torture/builtin-fp-int-inexact-trunc.c: New test.
> > ---
> >
> > Change from v1: add flag_trapping_math into the condition.
> >
> > Bootstrapped and regtested on x86_64-linux-gnu. Ok for trunk?
> >
> > gcc/convert.cc | 3 ++-
> > .../gcc.dg/torture/builtin-fp-int-inexact-trunc.c | 12 ++++++++++++
> > 2 files changed, 14 insertions(+), 1 deletion(-)
> > create mode 100644 gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-trunc.c
> >
> > diff --git a/gcc/convert.cc b/gcc/convert.cc
> > index 46c8bcb31f8..f214b750188 100644
> > --- a/gcc/convert.cc
> > +++ b/gcc/convert.cc
> > @@ -591,7 +591,8 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
> > CASE_FLT_FN (BUILT_IN_TRUNC):
> > CASE_FLT_FN_FLOATN_NX (BUILT_IN_TRUNC):
> > if (call_expr_nargs (s_expr) != 1
> > - || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (CALL_EXPR_ARG (s_expr, 0))))
> > + || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (CALL_EXPR_ARG (s_expr, 0)))
> > + || (!flag_fp_int_builtin_inexact && flag_trapping_math))
> > break;
> > return convert_to_integer_1 (type, CALL_EXPR_ARG (s_expr, 0),
> > dofold);
> > diff --git a/gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-trunc.c b/gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-trunc.c
> > new file mode 100644
> > index 00000000000..09731183621
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-trunc.c
> > @@ -0,0 +1,12 @@
> > +/* Test -fno-fp-int-builtin-inexact. */
> > +/* { dg-do compile } */
> > +/* { dg-options "-fno-fp-int-builtin-inexact -fdump-tree-original" } */
> > +
> > +long
> > +x (double y)
> > +{
> > + return __builtin_trunc (y);
> > +}
> > +
> > +/* Optimization should not discard the __builtin_trunc call. */
> > +/* { dg-final { scan-tree-dump "__builtin_trunc" "original" } } */
>
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PING^2: [PATCH v2] Only allow (int)trunc(x) to (int)x simplification with -ffp-int-builtin-inexact [PR107723]
2023-12-11 6:39 ` PING^2: " Xi Ruoyao
@ 2023-12-11 8:07 ` Richard Biener
0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2023-12-11 8:07 UTC (permalink / raw)
To: Xi Ruoyao; +Cc: gcc-patches, Joseph Myers
On Mon, Dec 11, 2023 at 7:39 AM Xi Ruoyao <xry111@xry111.site> wrote:
>
> Ping again.
OK, sorry for the delay.
Richard.
> On Fri, 2023-12-01 at 13:44 +0800, Xi Ruoyao wrote:
> > Ping.
> >
> > On Fri, 2023-11-24 at 17:09 +0800, Xi Ruoyao wrote:
> > > With -fno-fp-int-builtin-inexact, trunc is not allowed to raise
> > > FE_INEXACT and it should produce an integral result (if the input is not
> > > NaN or Inf). Thus FE_INEXACT should not be raised.
> > >
> > > But (int)x may raise FE_INEXACT when x is a non-integer, non-NaN, and
> > > non-Inf value. C23 recommends to do so in a footnote.
> > >
> > > Thus we should not simplify (int)trunc(x) to (int)x if
> > > -fno-fp-int-builtin-inexact is in-effect.
> > >
> > > gcc/ChangeLog:
> > >
> > > PR middle-end/107723
> > > * convert.cc (convert_to_integer_1) [case BUILT_IN_TRUNC]: Break
> > > early if !flag_fp_int_builtin_inexact and flag_trapping_math.
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > > PR middle-end/107723
> > > * gcc.dg/torture/builtin-fp-int-inexact-trunc.c: New test.
> > > ---
> > >
> > > Change from v1: add flag_trapping_math into the condition.
> > >
> > > Bootstrapped and regtested on x86_64-linux-gnu. Ok for trunk?
> > >
> > > gcc/convert.cc | 3 ++-
> > > .../gcc.dg/torture/builtin-fp-int-inexact-trunc.c | 12 ++++++++++++
> > > 2 files changed, 14 insertions(+), 1 deletion(-)
> > > create mode 100644 gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-trunc.c
> > >
> > > diff --git a/gcc/convert.cc b/gcc/convert.cc
> > > index 46c8bcb31f8..f214b750188 100644
> > > --- a/gcc/convert.cc
> > > +++ b/gcc/convert.cc
> > > @@ -591,7 +591,8 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
> > > CASE_FLT_FN (BUILT_IN_TRUNC):
> > > CASE_FLT_FN_FLOATN_NX (BUILT_IN_TRUNC):
> > > if (call_expr_nargs (s_expr) != 1
> > > - || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (CALL_EXPR_ARG (s_expr, 0))))
> > > + || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (CALL_EXPR_ARG (s_expr, 0)))
> > > + || (!flag_fp_int_builtin_inexact && flag_trapping_math))
> > > break;
> > > return convert_to_integer_1 (type, CALL_EXPR_ARG (s_expr, 0),
> > > dofold);
> > > diff --git a/gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-trunc.c b/gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-trunc.c
> > > new file mode 100644
> > > index 00000000000..09731183621
> > > --- /dev/null
> > > +++ b/gcc/testsuite/gcc.dg/torture/builtin-fp-int-inexact-trunc.c
> > > @@ -0,0 +1,12 @@
> > > +/* Test -fno-fp-int-builtin-inexact. */
> > > +/* { dg-do compile } */
> > > +/* { dg-options "-fno-fp-int-builtin-inexact -fdump-tree-original" } */
> > > +
> > > +long
> > > +x (double y)
> > > +{
> > > + return __builtin_trunc (y);
> > > +}
> > > +
> > > +/* Optimization should not discard the __builtin_trunc call. */
> > > +/* { dg-final { scan-tree-dump "__builtin_trunc" "original" } } */
> >
>
> --
> Xi Ruoyao <xry111@xry111.site>
> School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-12-11 8:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-24 9:09 [PATCH v2] Only allow (int)trunc(x) to (int)x simplification with -ffp-int-builtin-inexact [PR107723] Xi Ruoyao
2023-12-01 5:44 ` Ping: " Xi Ruoyao
2023-12-11 6:39 ` PING^2: " Xi Ruoyao
2023-12-11 8:07 ` 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).