]> git.ipfire.org Git - thirdparty/gcc.git/commit
MATCH: Simplify `(X &| B) CMP X` if possible [PR 101590]
authorAndrew Pinski <apinski@marvell.com>
Wed, 13 Sep 2023 01:24:22 +0000 (18:24 -0700)
committerAndrew Pinski <pinskia@gmail.com>
Fri, 27 Oct 2023 07:49:30 +0000 (00:49 -0700)
commita5e69e94591ae282857d59e868ff6cea7306c802
tree14ce48bb0a1eeed23e5f131ce19c7099595e08d9
parent7eed861e8ca3f533e56dea6348573caa09f16f5e
MATCH: Simplify `(X &| B) CMP X` if possible [PR 101590]

I noticed we were missing these simplifications so let's add them.

This adds the following simplifications:
U & N <= U  -> true
U & N >  U  -> false
When U is known to be as non-negative.

When N is also known to be non-negative, this is also true:
U | N <  U  -> false
U | N >= U  -> true

When N is a negative integer, the result flips and we get:
U | N <  U  -> true
U | N >= U  -> false

We could extend this later on to be the case where we know N
is nonconstant but is known to be negative.

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

PR tree-optimization/101590
PR tree-optimization/94884

gcc/ChangeLog:

* match.pd (`(X BIT_OP Y) CMP X`): New pattern.

gcc/testsuite/ChangeLog:

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