https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103193
--- Comment #5 from joseph at codesourcery dot com <joseph at codesourcery dot
com> ---
On Fri, 12 Nov 2021, rguenth at gcc dot gnu.org via Gcc-bugs wrote:
> /* Simplify comparison of something with itself. For IEEE
> floating-point, we can only do some of these simplifications. */
> (for cmp (eq ge le)
> (simplify
> (cmp @0 @0)
> (if (! FLOAT_TYPE_P (TREE_TYPE (@0))
> || ! HONOR_NANS (@0))
> { constant_boolean_node (true, type); }
> (if (cmp != EQ_EXPR)
> (eq @0 @0)))))
>
> does this. The folding to == happens unconditionally. As I understand you
> the condition that applies to the constant folding should apply to the
> folding to EQ as well, which means we effectively need to remove the
> canonicalization to EQ (since when it would be valid we can fold to constant
> true)?
It's invalid with -ftrapping-math because it loses an exception. With
-fno-trapping-math, but NaNs supported, you can convert to EQ but can't
fold to constant true.