https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67052

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
This means that the ABS_EXPR<x> < 0 code is correct in simplifying
NaN < 0 to true and it is correct to _not_ simplify NaN >= 0 to true.

But at the same time it has to do the same as fold_relational_const and
preserve traps with -ftrapping-math for the ordered compares.

So the following patch should fix the inconsistency and avoid the wrong-code
issue in the ABS_EXPR<x> < 0 folding:

Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c    (revision 226387)
+++ gcc/fold-const.c    (working copy)
@@ -11634,7 +11455,9 @@ fold_binary_loc (location_t loc,
       /* Convert ABS_EXPR<x> < 0 to false.  */
       strict_overflow_p = false;
       if (code == LT_EXPR
-         && (integer_zerop (arg1) || real_zerop (arg1))
+         && (integer_zerop (arg1)
+             || ((! HONOR_NANS (arg0) || !flag_trapping_math)
+                 && real_zerop (arg1)))
          && tree_expr_nonnegative_warnv_p (arg0, &strict_overflow_p))
        {
          if (strict_overflow_p)

Reply via email to