diff options
author | Wilco Dijkstra <wilco@gcc.gnu.org> | 2017-11-07 12:38:55 +0000 |
---|---|---|
committer | Wilco Dijkstra <wilco@gcc.gnu.org> | 2017-11-07 12:38:55 +0000 |
commit | 6a435314929c9dc355c0f8d1c3299e1214ce580f (patch) | |
tree | 70971fd48048e5c514ac4e25841ff7ca4f9d2224 | |
parent | 4349b15f97fcbb6b7cdd96bb5bff0af1eb78e653 (diff) | |
download | gcc-6a435314929c9dc355c0f8d1c3299e1214ce580f.zip gcc-6a435314929c9dc355c0f8d1c3299e1214ce580f.tar.gz gcc-6a435314929c9dc355c0f8d1c3299e1214ce580f.tar.bz2 |
PR71026: Canonicalize negates in division
Canonicalize x / (- y) into (-x) / y.
This moves negates out of the RHS of a division in order to
allow further simplifications and potentially more reciprocal CSEs.
2017-11-07 Wilco Dijkstra <wdijkstr@arm.com>
Jackson Woodruff <jackson.woodruff@arm.com>
gcc/
PR tree-optimization/71026
* match.pd: Canonicalize negate in division.
testsuite/
PR 71026/tree-optimization/71026
* gcc.dg/div_neg: New test.
From-SVN: r254497
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/match.pd | 5 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/div_neg.c | 10 |
4 files changed, 28 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ad93a20..2fb808b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-11-07 Wilco Dijkstra <wdijkstr@arm.com> + Jackson Woodruff <jackson.woodruff@arm.com> + + PR tree-optimization/71026 + * match.pd: Canonicalize negate in division. + 2017-11-07 Sudakshina Das <sudi.das@arm.com> PR middle-end/80131 diff --git a/gcc/match.pd b/gcc/match.pd index 49134bcb..903c065 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -354,6 +354,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (rdiv @0 (rdiv:s @1 @2)) (mult (rdiv @0 @1) @2))) +/* Simplify x / (- y) to -x / y. */ +(simplify + (rdiv @0 (negate @1)) + (rdiv (negate @0) @1)) + /* Optimize (X & (-A)) / A where A is a power of 2, to X >> log2(A) */ (for div (trunc_div ceil_div floor_div round_div exact_div) (simplify diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2032379..8d41c84 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,7 +1,13 @@ +2017-10-17 Wilco Dijkstra <wdijkstr@arm.com> + Jackson Woodruff <jackson.woodruff@arm.com> + + PR tree-optimization/71026 + * gcc.dg/div_neg: New test. + 2017-11-07 Sudakshina Das <sudi.das@arm.com> PR middle-end/80131 - * testsuite/gcc.dg/pr80131-1.c: New Test. + * gcc.dg/pr80131-1.c: New Test. 2017-11-07 Marc Glisse <marc.glisse@inria.fr> diff --git a/gcc/testsuite/gcc.dg/div_neg.c b/gcc/testsuite/gcc.dg/div_neg.c new file mode 100644 index 0000000..da499cd --- /dev/null +++ b/gcc/testsuite/gcc.dg/div_neg.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +float +div_neg (float x, float y) +{ + return (-x / y) * (x / -y); +} + +/* { dg-final { scan-tree-dump-times " / " 1 "optimized" } } */ |