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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-05-17
                 CC|                            |rguenth at gcc dot gnu.org
          Component|rtl-optimization            |middle-end
     Ever confirmed|0                           |1

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #6)
> What does tree_expr_nonnegative_p call non-negative? A natural definition
> would exclude NaN, but for REAL_CST we just return ! REAL_VALUE_NEGATIVE.

Is there sth like -NaN?!

Anyway, the bug is clearly in tree_expr_nonnegative_p and siblings.  Btw,
tree_binary_nonzero_warnv_p looks similarly suspicious.

I guess first of all

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index faa184a2bbd..cb3de26f9f1 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -12949,7 +12949,8 @@ tree_single_nonnegative_warnv_p (tree t, bool
*strict_overflow_p, int depth)
       return tree_int_cst_sgn (t) >= 0;

     case REAL_CST:
-      return ! REAL_VALUE_NEGATIVE (TREE_REAL_CST (t));
+      return (! REAL_VALUE_ISNAN (TREE_REAL_CST (t))
+             && ! REAL_VALUE_NEGATIVE (TREE_REAL_CST (t)));

     case FIXED_CST:
       return ! FIXED_VALUE_NEGATIVE (TREE_FIXED_CST (t));

but then how do we want to deal with MAX_EXPR (and MIN_EXPR which after the
above could see an optimization for min (NaN, x)?).  We'd have to special
case real-type MAX_EXPR (what about real complex/vector? 
tree_single_nonnegative_warnv_p doesn't handle complex/vector constants
but at least we should be correct in the uplevel treatment).

Reply via email to