Simplify floating point comparisons
authorWilco Dijkstra <wdijkstr@arm.com>
Wed, 14 Nov 2018 12:45:29 +0000 (12:45 +0000)
committerWilco Dijkstra <wilco@gcc.gnu.org>
Wed, 14 Nov 2018 12:45:29 +0000 (12:45 +0000)
commit5e21d7651ef002ba2ca0ad3038b8736c47919471
tree5586a58c4cc31595b4cdedf33ea852fd97d90fc8
parent8cca0163fb468842f85ac8e8638ea6d1ca2f9181
Simplify floating point comparisons

This patch implements some of the optimizations discussed in PR71026.

Simplify (C / x >= 0.0) into x >= 0.0 with -funsafe-math-optimizations
(since C / x can underflow to zero if x is huge, it's not safe otherwise).
If C is negative the comparison is reversed.

Simplify (x * C1) > C2 into x > (C2 / C1) with -funsafe-math-optimizations.
If C1 is negative the comparison is reversed.

    gcc/
PR 71026/tree-optimization
* match.pd: Simplify floating point comparisons.

    gcc/testsuite/
PR 71026/tree-optimization
* gcc.dg/div-cmp-1.c: New test.
* gcc.dg/div-cmp-2.c: New test.

Co-Authored-By: Jackson Woodruff <jackson.woodruff@arm.com>
From-SVN: r266142
gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/div-cmp-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/div-cmp-2.c [new file with mode: 0644]