]>
git.ipfire.org Git - thirdparty/gcc.git/commit
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.