Fix folding of Inf/NaN comparisons for -ftrapping-math (PR tree-optimization/64811).
commit38f4caae0c95ee6d767213ddc3c09d7e3b224cae
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 9 Jan 2018 13:25:38 +0000 (9 13:25 +0000)
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 9 Jan 2018 13:25:38 +0000 (9 13:25 +0000)
treea89520fd45e90056d90ab7810d9c09d60ed7698d
parente56a070cadd948b81a5b769e17c8c1162829de27
Fix folding of Inf/NaN comparisons for -ftrapping-math (PR tree-optimization/64811).

The folding of comparisons against Inf (to constants or comparisons
with the maximum finite value) has various cases where it introduces
or loses "invalid" exceptions for comparisons with NaNs.

Folding x > +Inf to 0 should not be about HONOR_SNANS - ordered
comparisons of both quiet and signaling NaNs should raise invalid.

x <= +Inf is not the same as x == x, because again that loses an
exception (equality comparisons don't raise exceptions except for
signaling NaNs).

x == +Inf is not the same as x > DBL_MAX, and a similar issue applies
with the x != +Inf case - that transformation causes a spurious
exception.

This patch fixes the conditionals on the folding to avoid such
introducing or losing exceptions.

Bootstrapped with no regressions on x86_64-pc-linux-gnu (where the
cases involving spurious exceptions wouldn't have failed anyway before
GCC 8 because of unordered comparisons wrongly always having formerly
been used by the back end).  Also tested for powerpc-linux-gnu
soft-float that this fixes many glibc math/ test failures that arose
in that configuration because this folding affected the IBM long
double support in libgcc (no such failures appeared for hard-float
because of the bug of powerpc hard-float always using unordered
comparisons) - some failures remain, but I believe them to be
unrelated.

PR tree-optimization/64811
gcc:
* match.pd: When optimizing comparisons with Inf, avoid
introducing or losing exceptions from comparisons with NaN.

gcc/testsuite:
* gcc.dg/torture/inf-compare-1.c, gcc.dg/torture/inf-compare-2.c,
gcc.dg/torture/inf-compare-3.c, gcc.dg/torture/inf-compare-4.c,
gcc.dg/torture/inf-compare-5.c, gcc.dg/torture/inf-compare-6.c,
gcc.dg/torture/inf-compare-7.c, gcc.dg/torture/inf-compare-8.c:
New tests.
* gcc.c-torture/execute/ieee/fp-cmp-7.x: New file.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@256380 138bc75d-0d04-0410-961f-82ee72b054a4
12 files changed:
gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/ieee/fp-cmp-7.x [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/inf-compare-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/inf-compare-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/inf-compare-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/inf-compare-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/inf-compare-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/inf-compare-6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/inf-compare-7.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/inf-compare-8.c [new file with mode: 0644]