diff mbox series

ubsan: Don't test for NaNs if those do not exist (PR97926)

Message ID 0508de81df1d22ac611bc95efc5fb24235811648.1616166493.git.segher@kernel.crashing.org
State New
Headers show
Series ubsan: Don't test for NaNs if those do not exist (PR97926) | expand

Commit Message

Segher Boessenkool March 19, 2021, 3:12 p.m. UTC
Tested on powerpc64-linux {-m32,-m64}.  No regressions.  Is this okay
for trunk?


Segher


2021-03-19  Segher Boessenkool  <segher@kernel.crashing.org>

	PR target/97926
	* ubsan.c (ubsan_instrument_float_cast): Don't test for unordered if
	there are no NaNs.
---
 gcc/ubsan.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Jeff Law March 19, 2021, 5:07 p.m. UTC | #1
On 3/19/2021 9:12 AM, Segher Boessenkool wrote:
> Tested on powerpc64-linux {-m32,-m64}.  No regressions.  Is this okay
> for trunk?
>
>
> Segher
>
>
> 2021-03-19  Segher Boessenkool  <segher@kernel.crashing.org>
>
> 	PR target/97926
> 	* ubsan.c (ubsan_instrument_float_cast): Don't test for unordered if
> 	there are no NaNs.

OK

jeff
diff mbox series

Patch

diff --git a/gcc/ubsan.c b/gcc/ubsan.c
index d752b897d642..1089aef639ff 100644
--- a/gcc/ubsan.c
+++ b/gcc/ubsan.c
@@ -1890,8 +1890,16 @@  ubsan_instrument_float_cast (location_t loc, tree type, tree expr)
   else
     return NULL_TREE;
 
-  t = fold_build2 (UNLE_EXPR, boolean_type_node, expr, min);
-  tt = fold_build2 (UNGE_EXPR, boolean_type_node, expr, max);
+  if (HONOR_NANS (mode))
+    {
+      t = fold_build2 (UNLE_EXPR, boolean_type_node, expr, min);
+      tt = fold_build2 (UNGE_EXPR, boolean_type_node, expr, max);
+    }
+  else
+    {
+      t = fold_build2 (LE_EXPR, boolean_type_node, expr, min);
+      tt = fold_build2 (GE_EXPR, boolean_type_node, expr, max);
+    }
   t = fold_build2 (TRUTH_OR_EXPR, boolean_type_node, t, tt);
   if (integer_zerop (t))
     return NULL_TREE;