expansion: Further improve double-word modulo, division and divmod [PR97459]
authorJakub Jelinek <jakub@redhat.com>
Wed, 2 Dec 2020 10:32:19 +0000 (11:32 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 2 Dec 2020 10:40:47 +0000 (11:40 +0100)
commit037fe26ee1ac18581bf0ad646d48591c97d10bd3
treea6f69e57d3e6391e15795c1382babe8437afd09b
parent337d6362458ab033d3bfe287dda37f9da5577406
expansion: Further improve double-word modulo, division and divmod [PR97459]

The following patch implements what Thomas wrote about, in particular
that we can handle also double-word divison by the constants for which
the earlier patch optimized modulo (if it would be otherwise a library
call) and that we can also easily handle such constants shifted to the left.
Unfortunately, seems CSE isn't able to optimize away the two almost
identical sequences (one to compute remainder, one to compute quotient),
probably because of the ADD_OVERFLOW introduced jumps, so the patch also
adjusts expand_DIVMOD.

2020-12-02  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/97459
* optabs.h (expand_doubleword_divmod): Declare.
* optabs.c (expand_doubleword_divmod): New function.
(expand_binop): Use it.
* internal-fn.c (expand_DIVMOD): Likewise.

* gcc.target/i386/pr97282.c (foo): Use 123456 divisor instead of
10.
* gcc.dg/pr97459-1.c (TESTS): Add tests for 10, 12 and
6144.
* gcc.dg/pr97459-2.c (TESTS): Likewise.
* gcc.dg/pr97459-3.c: New test.
* gcc.dg/pr97459-4.c: New test.
* gcc.dg/pr97459-5.c: New test.
* gcc.dg/pr97459-6.c: New test.
gcc/internal-fn.c
gcc/optabs.c
gcc/optabs.h
gcc/testsuite/gcc.dg/pr97459-1.c
gcc/testsuite/gcc.dg/pr97459-2.c
gcc/testsuite/gcc.dg/pr97459-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr97459-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr97459-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr97459-6.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr97282.c