expand: Expand x / y * y as x - x % y if the latter is cheaper [PR96696]
authorJakub Jelinek <jakub@redhat.com>
Tue, 27 Apr 2021 12:45:45 +0000 (14:45 +0200)
committerJakub Jelinek <jakub@redhat.com>
Tue, 27 Apr 2021 12:45:45 +0000 (14:45 +0200)
commit3dcd1334b4f522352b80814513fdca902fc2a207
treeba22865f280b62b887ab9dc5c9c065aeebcdcf32
parenteea82246290010addf7f6be71a71b51079b3cb5d
expand: Expand x / y * y as x - x % y if the latter is cheaper [PR96696]

The following patch tests both x / y * y and x - x % y expansion for the
former GIMPLE code and chooses the cheaper of those sequences.

2021-04-27  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/96696
* expr.c (expand_expr_divmod): New function.
(expand_expr_real_2) <case TRUNC_DIV_EXPR>: Use it for truncations and
divisions.  Formatting fixes.
<case MULT_EXPR>: Optimize x / y * y as x - x % y if the latter is
cheaper.

* gcc.target/i386/pr96696.c: New test.
gcc/expr.c
gcc/testsuite/gcc.target/i386/pr96696.c [new file with mode: 0644]