]> git.ipfire.org Git - thirdparty/gcc.git/commit
Add a != MIN/MAX_VALUE_CST ? CST-+1 : a to minmax_from_comparison
authorAndrew Pinski <apinski@marvell.com>
Tue, 16 May 2023 21:26:41 +0000 (14:26 -0700)
committerAndrew Pinski <apinski@marvell.com>
Tue, 30 May 2023 15:43:23 +0000 (08:43 -0700)
commit45466eecf5ef669164c0922e5be8fd288b144886
tree7efdbe9befafc1337527c3567ac6a2b2f3e46691
parent17cca3c43e2f496dcef0ba79e04979b49439e0c3
Add a != MIN/MAX_VALUE_CST ? CST-+1 : a to minmax_from_comparison

This patch adds the support for match that was implemented for PR 87913 in phiopt.
It implements it by adding support to minmax_from_comparison for the check.
It uses the range information if available which allows to produce MIN/MAX expression
when comparing against the lower/upper bound of the range instead of lower/upper
of the type.

minmax-20.c is the new testcase which tests the ranges part.

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

gcc/ChangeLog:

* fold-const.cc (minmax_from_comparison): Add support for NE_EXPR.
* match.pd ((cond (cmp (convert1? x) c1) (convert2? x) c2) pattern):
Add ne as a possible cmp.
((a CMP b) ? minmax<a, c> : minmax<b, c> pattern): Likewise.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/minmax-22.c: New test.
gcc/fold-const.cc
gcc/match.pd
gcc/testsuite/gcc.dg/tree-ssa/minmax-22.c [new file with mode: 0644]