https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93902
--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> --- The current optimization in match.pd is an equivalence, it replaces (double)i==(double)j with i==j when the conversion is always exact. Here, what we would want is that inside the a==b branch, the compiler would arbitrarily replace one of a or b with the other. Then it would easily CSE the conversions to double and fold the self-comparison. I thought we used to do such replacements in some cases, but apparently not in this case.