PR middle-end/88173: More constant folding of NaN comparisons.
This patch tackles PR middle-end/88173 where the order of operands in
a comparison affects constant folding. As diagnosed by Jason Merrill,
"match.pd handles these comparisons very differently". The history is
that the middle end, typically canonicalizes comparisons to place
constants on the right, but when a comparison contains two constants
we need to check/transform both constants, i.e. on both the left and the
right. Hence the added lines below duplicate for @0 the same transform
applied a few lines above for @1.
Whilst preparing the testcase, I noticed that this transformation is
incorrectly disabled with -fsignaling-nans even when both operands are
known not be be signaling NaNs, so I've corrected that and added a
second test case. Unfortunately, c-c++-common/pr57371-4.c then starts
failing, as it doesn't distinguish QNaNs (which are quiet) from SNaNs
(which signal), so this patch includes a minor tweak to the expected
behaviour for QNaNs in that existing test.
2021-09-19 Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
PR middle-end/88173
* match.pd (cmp @0 REAL_CST@1): When @0 is also REAL_CST, apply
the same transformations as to @1. For comparisons against NaN,
don't check HONOR_SNANS but confirm that neither operand is a
signaling NaN.
gcc/testsuite/ChangeLog
PR middle-end/88173
* c-c++-common/pr57371-4.c: Tweak/correct test case for QNaNs.
* g++.dg/pr88173-1.C: New test case.
* g++.dg/pr88173-2.C: New test case.