Factor out division by squares
authorJackson Woodruff <jackson.woodruff@arm.com>
Fri, 24 Nov 2017 16:03:13 +0000 (16:03 +0000)
committerWilco Dijkstra <wilco@gcc.gnu.org>
Fri, 24 Nov 2017 16:03:13 +0000 (16:03 +0000)
commit19cf3a368544af31e3791c27e3c9be9b01e71851
tree4a8138b582ded97f36d36a37fd7c48fe089bb91d
parent15b6695ac534148a10dd5a5f266bf2e49316dc32
Factor out division by squares

This patch implements the some of the division optimizations discussed in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71026.

The division reciprocal optimization now handles divisions by squares:

     x / (y * y) -> x  * (1 / y) * (1 / y)

This requires at least one more division by y before it triggers - the
3 divisions of (1/ y) are then CSEd into a single division.  Overall
this changes 1 division into 1 multiply, which is generally much faster.

2017-11-24  Jackson Woodruff  <jackson.woodruff@arm.com>

    gcc/
PR tree-optimization/71026
* tree-ssa-math-opts (is_division_by_square, is_square_of): New.
(insert_reciprocals): Change to insert reciprocals before a division
by a square and to insert the square of a reciprocal.
(execute_cse_reciprocals_1): Change to consider division by a square.
(register_division_in): Add importance parameter.

    testsuite/
PR tree-optimization/71026
* gfortran.dg/extract_recip_1.f: New test.
* gcc.dg/extract_recip_3.c: New test.
* gcc.dg/extract_recip_4.c: New test.

From-SVN: r255141
gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/extract_recip_3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/extract_recip_4.c [new file with mode: 0644]
gcc/testsuite/gfortran.dg/extract_recip_1.f [new file with mode: 0644]
gcc/tree-ssa-math-opts.c