MATCH: Simplify `(X % Y) < Y` pattern.

Message ID 20230912221013.1456582-1-apinski@marvell.com
State Accepted
Headers
Series MATCH: Simplify `(X % Y) < Y` pattern. |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Andrew Pinski Sept. 12, 2023, 10:10 p.m. UTC
  This merges the two patterns to catch
`(X % Y) < Y` and `Y > (X % Y)` into one by
using :c on the comparison operator.
It does not change any code generation nor
anything else. It is more to allow for better
maintainability of this pattern.

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

gcc/ChangeLog:

	* match.pd (`Y > (X % Y)`): Merge
	into ...
	(`(X % Y) < Y`): Pattern by adding `:c`
	on the comparison.
---
 gcc/match.pd | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
  

Comments

Richard Biener Sept. 13, 2023, 6:52 a.m. UTC | #1
On Wed, Sep 13, 2023 at 12:11 AM Andrew Pinski via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> This merges the two patterns to catch
> `(X % Y) < Y` and `Y > (X % Y)` into one by
> using :c on the comparison operator.
> It does not change any code generation nor
> anything else. It is more to allow for better
> maintainability of this pattern.
>
> OK? Bootstrapped and tested on x86_64-linux-gnu.

OK.

> gcc/ChangeLog:
>
>         * match.pd (`Y > (X % Y)`): Merge
>         into ...
>         (`(X % Y) < Y`): Pattern by adding `:c`
>         on the comparison.
> ---
>  gcc/match.pd | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 39c7ea1088f..24fd29863fb 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -1483,14 +1483,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>  /* X % Y is smaller than Y.  */
>  (for cmp (lt ge)
>   (simplify
> -  (cmp (trunc_mod @0 @1) @1)
> +  (cmp:c (trunc_mod @0 @1) @1)
>    (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
>     { constant_boolean_node (cmp == LT_EXPR, type); })))
> -(for cmp (gt le)
> - (simplify
> -  (cmp @1 (trunc_mod @0 @1))
> -  (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
> -   { constant_boolean_node (cmp == GT_EXPR, type); })))
>
>  /* x | ~0 -> ~0  */
>  (simplify
> --
> 2.31.1
>
  

Patch

diff --git a/gcc/match.pd b/gcc/match.pd
index 39c7ea1088f..24fd29863fb 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1483,14 +1483,9 @@  DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* X % Y is smaller than Y.  */
 (for cmp (lt ge)
  (simplify
-  (cmp (trunc_mod @0 @1) @1)
+  (cmp:c (trunc_mod @0 @1) @1)
   (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
    { constant_boolean_node (cmp == LT_EXPR, type); })))
-(for cmp (gt le)
- (simplify
-  (cmp @1 (trunc_mod @0 @1))
-  (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
-   { constant_boolean_node (cmp == GT_EXPR, type); })))
 
 /* x | ~0 -> ~0  */
 (simplify