match.pd: Optimize (x < 0) ^ (y < 0) to (x ^ y) < 0 etc. [PR96681]
authorJakub Jelinek <jakub@redhat.com>
Fri, 15 Jan 2021 20:10:44 +0000 (21:10 +0100)
committerJakub Jelinek <jakub@redhat.com>
Fri, 15 Jan 2021 20:10:44 +0000 (21:10 +0100)
commit5c046034e3ea61dd68965154a398f8f813daf8f2
tree3bd073451c69e3dbb6f9eff9dac0a17f6f6d0e49
parente63c2161d09903ca5c07b1eb0d8c0a1a17967499
match.pd: Optimize (x < 0) ^ (y < 0) to (x ^ y) < 0 etc. [PR96681]

This patch simplifies comparisons that test the sign bit xored together.
If the comparisons are both < 0 or both >= 0, then we should xor the operands
together and compare the result to < 0, if the comparisons are different,
we should compare to >= 0.

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

PR tree-optimization/96681
* match.pd ((x < 0) ^ (y < 0) to (x ^ y) < 0): New simplification.
((x >= 0) ^ (y >= 0) to (x ^ y) < 0): Likewise.
((x < 0) ^ (y >= 0) to (x ^ y) >= 0): Likewise.
((x >= 0) ^ (y < 0) to (x ^ y) >= 0): Likewise.

* gcc.dg/tree-ssa/pr96681.c: New test.
gcc/match.pd
gcc/testsuite/gcc.dg/tree-ssa/pr96681.c [new file with mode: 0644]