MATCH: Move X <= MAX(X, Y) before MIN (X, C1) < C2 pattern

Since matching C1 as C2 here will decrease how much other simplifications
will need to happen to get the final answer.

OK? Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* match.pd (`X <= MAX(X, Y)`):
	Move before `MIN (X, C1) < C2` pattern.
This commit is contained in:
Andrew Pinski 2023-09-12 05:27:24 +00:00
parent 06bedc3860
commit 4a937fa94f

View file

@ -3947,13 +3947,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (wi::lt_p (wi::to_wide (@1), wi::to_wide (@2),
TYPE_SIGN (TREE_TYPE (@0))))
(cmp @0 @2)))))
/* MIN (X, C1) < C2 -> X < C2 || C1 < C2 */
(for minmax (min min max max min min max max )
cmp (lt le gt ge gt ge lt le )
comb (bit_ior bit_ior bit_ior bit_ior bit_and bit_and bit_and bit_and)
(simplify
(cmp (minmax @0 INTEGER_CST@1) INTEGER_CST@2)
(comb (cmp @0 @2) (cmp @1 @2))))
/* X <= MAX(X, Y) -> true
X > MAX(X, Y) -> false
@ -3965,6 +3958,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(cmp:c @0 (minmax:c @0 @1))
{ constant_boolean_node (cmp == GE_EXPR || cmp == LE_EXPR, type); } ))
/* MIN (X, C1) < C2 -> X < C2 || C1 < C2 */
(for minmax (min min max max min min max max )
cmp (lt le gt ge gt ge lt le )
comb (bit_ior bit_ior bit_ior bit_ior bit_and bit_and bit_and bit_and)
(simplify
(cmp (minmax @0 INTEGER_CST@1) INTEGER_CST@2)
(comb (cmp @0 @2) (cmp @1 @2))))
/* Undo fancy ways of writing max/min or other ?: expressions, like
a - ((a - b) & -(a < b)) and a - (a - b) * (a < b) into (a < b) ? b : a.
People normally use ?: and that is what we actually try to optimize. */