On Mon, May 27, 2024 at 2:47 AM Andrew Pinski wrote:
>
> While working on adding matching of negative expressions of `a - b`,
> I noticed that we started to have "duplicated" patterns due to not having
> a way to match maybe negative expressions. So I went back to what I did for
> bit_not and decided to improve the situtation there so for some patterns
> where we had 2 operands of an expression where one could have been a bit_not,
> add back maybe_bit_not.
> This does not add maybe_bit_not in every place were bitwise_inverted_equal_p
> is used, just the ones were 2 operands of an expression could be swapped.
>
> Bootstrapped and tested on x86_64-linux-gnu with no regressions.
OK.
Richard.
> gcc/ChangeLog:
>
> * match.pd (bit_not_with_nop): Unconditionalize.
> (maybe_cmp): Likewise.
> (maybe_bit_not): New match pattern.
> (`~X & X`): Use maybe_bit_not and add `:c` back.
> (`~x ^ x`/`~x | x`): Likewise.
>
> Signed-off-by: Andrew Pinski
> ---
> gcc/match.pd | 14 ++
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 024e3350465..090ad4e08b0 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -167,7 +167,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>TYPE_VECTOR_SUBPARTS (TREE_TYPE (@0)))
>&& tree_nop_conversion_p (TREE_TYPE (type), TREE_TYPE (TREE_TYPE
> (@0))
>
> -#if GIMPLE
> /* These are used by gimple_bitwise_inverted_equal_p to simplify
> detection of BIT_NOT and comparisons. */
> (match (bit_not_with_nop @0)
> @@ -188,7 +187,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> (bit_xor@0 @1 @2)
> (if (INTEGRAL_TYPE_P (type)
>&& TYPE_PRECISION (type) == 1)))
> -#endif
> +/* maybe_bit_not is used to match what
> + is acceptable for bitwise_inverted_equal_p. */
> +(match (maybe_bit_not @0)
> + (bit_not_with_nop@0 @1))
> +(match (maybe_bit_not @0)
> + (INTEGER_CST@0))
> +(match (maybe_bit_not @0)
> + (maybe_cmp@0 @1))
>
> /* Transform likes of (char) ABS_EXPR <(int) x> into (char) ABSU_EXPR
> ABSU_EXPR returns unsigned absolute value of the operand and the operand
> @@ -1332,7 +1338,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>
> /* Simplify ~X & X as zero. */
> (simplify
> - (bit_and (convert? @0) (convert? @1))
> + (bit_and:c (convert? @0) (convert? (maybe_bit_not @1)))
> (with { bool wascmp; }
>(if (types_match (TREE_TYPE (@0), TREE_TYPE (@1))
> && bitwise_inverted_equal_p (@0, @1, wascmp))
> @@ -1597,7 +1603,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> /* ~x ^ x -> -1 */
> (for op (bit_ior bit_xor)
> (simplify
> - (op (convert? @0) (convert? @1))
> + (op:c (convert? @0) (convert? (maybe_bit_not @1)))
>(with { bool wascmp; }
> (if (types_match (TREE_TYPE (@0), TREE_TYPE (@1))
> && bitwise_inverted_equal_p (@0, @1, wascmp))
> --
> 2.43.0
>