simplify-rtx: Optimize (x - 1) * y + y [PR98334]
authorJakub Jelinek <jakub@redhat.com>
Tue, 5 Jan 2021 09:57:52 +0000 (10:57 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 5 Jan 2021 09:59:00 +0000 (10:59 +0100)
commit4615cde5d7ef281d4b554df411f82ad707f0a54d
tree69005f7b86e4e76b7fed0153ad53bb708f0966a6
parent6b69738c1e30ec31cb11dce1d9209e7a5b92301b
simplify-rtx: Optimize (x - 1) * y + y [PR98334]

We don't try to optimize for signed x, y (int) (x - 1U) * y + y
into x * y, we can't do that with signed x * y, because the former
is well defined for INT_MIN and -1, while the latter is not.
We could perhaps optimize it during isel or some very late optimization
where we'd turn magically flag_wrapv, but we don't do that yet.

This patch optimizes it in simplify-rtx.c, such that we can optimize
it during combine.

2021-01-05  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/98334
* simplify-rtx.c (simplify_context::simplify_binary_operation_1):
Optimize (X - 1) * Y + Y to X * Y or (X + 1) * Y - Y to X * Y.

* gcc.target/i386/pr98334.c: New test.
gcc/simplify-rtx.c
gcc/testsuite/gcc.target/i386/pr98334.c [new file with mode: 0644]