[PR31531] MATCH: Improve ~a < ~b and ~a < CST, allow a nop cast inbetween ~ and a/b
commit29a4453c7b8a86d242dab89b9e4d222749fd911e
authorAndrew Pinski <pinskia@gmail.com>
Sun, 15 Oct 2023 22:18:42 +0000 (15 15:18 -0700)
committerAndrew Pinski <pinskia@gmail.com>
Mon, 16 Oct 2023 16:59:56 +0000 (16 09:59 -0700)
treecd9af0d09b4ab05e184e8332b56bbd441db52319
parent7550130c8620085c4efdde3575190588795f9b61
[PR31531] MATCH: Improve ~a < ~b and ~a < CST, allow a nop cast inbetween ~ and a/b

Currently we able to simplify `~a CMP ~b` to `b CMP a` but we should allow a nop
conversion in between the `~` and the `a` which can show up. A similarly thing should
be done for `~a CMP CST`.

I had originally submitted the `~a CMP CST` case as
https://gcc.gnu.org/pipermail/gcc-patches/2021-November/585088.html;
I noticed we should do the same thing for the `~a CMP ~b` case and combined
it with that one here.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

PR tree-optimization/31531

gcc/ChangeLog:

* match.pd (~X op ~Y): Allow for an optional nop convert.
(~X op C): Likewise.

gcc/testsuite/ChangeLog:

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