[2/2] MATCH: Move `X <= MAX(X, Y)` before `MIN (X, C1) < C2` pattern

Message ID 20230912152542.1440800-2-apinski@marvell.com
State Unresolved
Headers
Series [1/2] MATCH: [PR111364] Add some more minmax cmp operand simplifications |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Andrew Pinski Sept. 12, 2023, 3:25 p.m. UTC
  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(-)
  

Comments

Richard Biener Sept. 13, 2023, 6:43 a.m. UTC | #1
On Tue, Sep 12, 2023 at 5:41 PM Andrew Pinski via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> 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.

OK

Richard.

> 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 36e3da4841b..34b67df784e 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -3931,13 +3931,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
> @@ -3949,6 +3942,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.  */
> --
> 2.31.1
>
  

Patch

diff --git a/gcc/match.pd b/gcc/match.pd
index 36e3da4841b..34b67df784e 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3931,13 +3931,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 
@@ -3949,6 +3942,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.  */