]> git.ipfire.org Git - thirdparty/gcc.git/commit
match: Add support for convert `((signed)x) < 0` to `x >= (unsigned)SIGNED_TYPE_MIN...
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Mon, 20 Oct 2025 22:48:43 +0000 (15:48 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Tue, 21 Oct 2025 09:26:09 +0000 (02:26 -0700)
commit07800a565abd20814468a4f84a988e0d95bf30b5
tree0a01045d6401e3d61b6b04acdd1cff5a57dfb876
parenta3c0112f554c676f6155db75ccab9d8393ed763c
match: Add support for convert `((signed)x) < 0` to `x >= (unsigned)SIGNED_TYPE_MIN` while detecting min/max [PR110068]

This copies the optimization which was done to fix PR 95699 to match detection of MIN/MAX
from minmax_replacement to match.
This is another step in getting rid of minmax_replacement in phiopt.  There are still a few
more min/max detections that needs to be handled before the removal. pr101024-1.c adds one
example of that but since the testcase currently passes I didn't xfail it.

pr110068-1.c adds a testcase which was not detected beforehand either.

Changes since v1:
* v2: Fix comment about how it is transformed.
      Use SIGNED_TYPE_MIN everywhere instead of mxing in SIGNED_TYPE_MAX too.

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/95699
PR tree-optimization/101024
PR tree-optimization/110068

gcc/ChangeLog:

* match.pd (`(type1)x CMP CST1 ? (type2)x : CST2`): Treat
`(signed)x </>= 0` as `x >=/< SIGNED_TYPE_MIN`

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr101024-1.c: New test.
* gcc.dg/tree-ssa/pr110068-1.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/match.pd
gcc/testsuite/gcc.dg/tree-ssa/pr101024-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr110068-1.c [new file with mode: 0644]