From 4a937fa94fde09ab96b494b32ed4d569a199c5be Mon Sep 17 00:00:00 2001 From: Andrew Pinski Date: Tue, 12 Sep 2023 05:27:24 +0000 Subject: [PATCH] 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. --- gcc/match.pd | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index ea4c7c5cf53..7ecf5568599 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -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. */