aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Sayle <roger@nextmovesoftware.com>2024-07-18 08:27:36 +0100
committerRoger Sayle <roger@nextmovesoftware.com>2024-07-18 08:30:31 +0100
commit030186cabe8128e752619e101768cf8823a42c38 (patch)
tree1b3e6a45de0e56da9163a648a17d63050f8fe902
parent0231b076dc98eb02e3289b21ace1757782e3917b (diff)
downloadgcc-030186cabe8128e752619e101768cf8823a42c38.zip
gcc-030186cabe8128e752619e101768cf8823a42c38.tar.gz
gcc-030186cabe8128e752619e101768cf8823a42c38.tar.bz2
Implement a -ftrapping-math/-fsignaling-nans TODO in match.pd.
I've been investigating some (float)i == CST optimizations for match.pd, and noticed there's already a TODO comment in match.pd that's relatively easy to implement. When CST is a NaN, we only need to worry about exceptions with flag_trapping_math, and equality/inequality tests for sNaN only behave differently to qNaN with -fsignaling-nans. These issues are related to PR 57371 and PR 106805 in bugzilla. 2024-07-18 Roger Sayle <roger@nextmovesoftware.com> gcc/ChangeLog * match.pd ((FTYPE) N CMP CST): Only worry about exceptions with flag_trapping_math, and about signaling NaNs with HONOR_SNANS. gcc/testsuite/ChangeLog * c-c++-common/pr57371-4.c: Update comment. * c-c++-common/pr57371-5.c: Add missing testcases from pr57371-4.c and update for -fno-signaling-nans -fno-trapping-math.
-rw-r--r--gcc/match.pd14
-rw-r--r--gcc/testsuite/c-c++-common/pr57371-4.c4
-rw-r--r--gcc/testsuite/c-c++-common/pr57371-5.c42
3 files changed, 47 insertions, 13 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 5cb399b..6818856 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6862,13 +6862,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
tree itype = TREE_TYPE (@0);
format_helper fmt (REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (@1))));
const REAL_VALUE_TYPE *cst = TREE_REAL_CST_PTR (@1);
- /* Be careful to preserve any potential exceptions due to
- NaNs. qNaNs are ok in == or != context.
- TODO: relax under -fno-trapping-math or
- -fno-signaling-nans. */
- bool exception_p
- = real_isnan (cst) && (cst->signalling
- || (cmp != EQ_EXPR && cmp != NE_EXPR));
+ /* Be careful to preserve any potential exceptions due to NaNs.
+ qNaNs are ok in == or != context. */
+ bool exception_p = real_isnan (cst)
+ && flag_trapping_math
+ && ((cmp != EQ_EXPR && cmp != NE_EXPR)
+ || (cst->signalling
+ && HONOR_SNANS (TREE_TYPE (@1))));
}
/* TODO: allow non-fitting itype and SNaNs when
-fno-trapping-math. */
diff --git a/gcc/testsuite/c-c++-common/pr57371-4.c b/gcc/testsuite/c-c++-common/pr57371-4.c
index f43f7c2..b0e539d 100644
--- a/gcc/testsuite/c-c++-common/pr57371-4.c
+++ b/gcc/testsuite/c-c++-common/pr57371-4.c
@@ -2,9 +2,7 @@
/* { dg-options "-O -fsignaling-nans -fdump-tree-original" } */
/* We can not get rid of comparison in tests below because of
- pending NaN exceptions.
-
- TODO: avoid under -fno-trapping-math. */
+ pending NaN exceptions. */
#define QNAN __builtin_nanf ("0")
#define SNAN __builtin_nansf ("0")
diff --git a/gcc/testsuite/c-c++-common/pr57371-5.c b/gcc/testsuite/c-c++-common/pr57371-5.c
index 8e18b0a..77decbe 100644
--- a/gcc/testsuite/c-c++-common/pr57371-5.c
+++ b/gcc/testsuite/c-c++-common/pr57371-5.c
@@ -2,11 +2,10 @@
/* { dg-options "-O -fno-signaling-nans -fno-trapping-math -fdump-tree-original" } */
/* We can not get rid of comparison in tests below because of
- pending NaN exceptions.
-
- TODO: avoid under -fno-trapping-math. */
+ pending NaN exceptions. */
#define QNAN __builtin_nanf ("0")
+#define SNAN __builtin_nansf ("0")
void nonfinite(unsigned short x) {
{
@@ -34,6 +33,43 @@ void nonfinite(unsigned short x) {
}
{
+ volatile int nonfinite_5;
+ nonfinite_5 = (float) x > SNAN;
+ /* { dg-final { scan-tree-dump "nonfinite_5 = 0" "original" } } */
+ }
+
+ {
+ volatile int nonfinite_6;
+ nonfinite_6 = (float) x >= SNAN;
+ /* { dg-final { scan-tree-dump "nonfinite_6 = 0" "original" } } */
+ }
+
+ {
+ volatile int nonfinite_7;
+ nonfinite_7 = (float) x < SNAN;
+ /* { dg-final { scan-tree-dump "nonfinite_7 = 0" "original" } } */
+ }
+
+ {
+ volatile int nonfinite_8;
+ nonfinite_8 = (float) x <= SNAN;
+ /* { dg-final { scan-tree-dump "nonfinite_8 = 0" "original" } } */
+ }
+
+ {
+ volatile int nonfinite_9;
+ nonfinite_9 = (float) x == SNAN;
+ /* { dg-final { scan-tree-dump "nonfinite_9 = 0" "original" } } */
+ }
+
+ {
+ volatile int nonfinite_10;
+ nonfinite_10 = (float) x != SNAN;
+ /* { dg-final { scan-tree-dump "nonfinite_10 = 1" "original" } } *
+ */
+ }
+
+ {
volatile int nonfinite_11;
nonfinite_11 = (float) x == QNAN;
/* { dg-final { scan-tree-dump "nonfinite_11 = 0" "original" } } */