]> git.ipfire.org Git - thirdparty/gcc.git/commit
match: Add `cmp - 1` simplification to `-icmp` [PR110949]
authorAndrew Pinski <quic_apinski@quicinc.com>
Sun, 20 Jul 2025 18:21:08 +0000 (11:21 -0700)
committerAndrew Pinski <quic_apinski@quicinc.com>
Mon, 21 Jul 2025 16:23:05 +0000 (09:23 -0700)
commitfa099f248e2462ecd5ab8b0cadd348aaf11bb093
treecd33ca6452ca465726e16431d506e751af72d4eb
parentdfab6593b05a65b5a475e0572e101bd56e3a2282
match: Add `cmp - 1` simplification to `-icmp` [PR110949]

I have seen this a few places though the testcase from PR 95906
is an obvious place where this shows up for sure.
This convert `cmp - 1` into `-icmp` as that form is more useful
in many cases.

Changes since v1:
* v2: Add check for outer type's precision being greater than 1.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/110949
PR tree-optimization/95906

gcc/ChangeLog:

* match.pd (cmp - 1): New pattern.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/cmp-2.c: New test.
* gcc.dg/tree-ssa/max-bitcmp-1.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/match.pd
gcc/testsuite/gcc.dg/tree-ssa/cmp-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/max-bitcmp-1.c [new file with mode: 0644]