Jiawei <jia...@iscas.ac.cn> writes:
> This patch adds a new simplification rule to `simplify-rtx.cc` that
> handles a common bit manipulation pattern involving a single-bit set
> and clear followed by XOR.
>
> The transformation targets RTL of the form:
>
>   (xor (and (rotate (~1) A) B) (ashift 1 A))
>
> which is semantically equivalent to:
>
>   B | (1 << A)
>
> and can verified by the g++.target/riscv/redundant-bitmap-2.C.
>
> - v2 log:
>   Update RTL format, remove commas.
>   Don't apply on SHIFT_COUNT_TRUNCATED target.
>   check '!side_effects_p' on XEXP (op1, 1).
>
> gcc/ChangeLog:
>
>       * simplify-rtx.cc (simplify_context::simplify_binary_operation_1): 
> Handle
> more logical simplifications.
>
> ---
>  gcc/simplify-rtx.cc | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
> index b34fd2f4b9e..ae6563c78b2 100644
> --- a/gcc/simplify-rtx.cc
> +++ b/gcc/simplify-rtx.cc
> @@ -4063,6 +4063,20 @@ simplify_context::simplify_binary_operation_1 
> (rtx_code code,
>         && rtx_equal_p (XEXP (XEXP (op0, 0), 0), op1))
>       return simplify_gen_binary (IOR, mode, XEXP (op0, 1), op1);
>  
> +      /* Convert (xor (and (rotate (~1) A) B) (ashift 1 A))
> +      into B | (1 << A).  */
> +      if (!SHIFT_COUNT_TRUNCATED

I meant it should be opposite: the fold should require SHIFT_COUNT_TRUNCATED
(reject !SHIFT_COUNT_TRUNCATED).

SHIFT_COUNT_TRUNCATED guarantees that, for a 32-bit shift, A==32 acts
like A==0.  With !SHIFT_COUNT_TRUNCATED, 1<<A might be zero instead.

I realise that doesn't help you though, since RISC-V is !SHIFT_COUNT_TRUNCATED
target.

Thanks,
Richard

> +       && GET_CODE (op0) == AND
> +       && GET_CODE (XEXP (op0, 0)) == ROTATE
> +       && CONST_INT_P (XEXP (XEXP (op0, 0), 0))
> +       && INTVAL (XEXP (XEXP (op0, 0), 0)) == -2
> +       && GET_CODE (op1) == ASHIFT
> +       && CONST_INT_P (XEXP (op1, 0))
> +       && INTVAL (XEXP (op1, 0)) == 1
> +       && rtx_equal_p (XEXP (XEXP (op0, 0), 1), XEXP (op1, 1))
> +       && !side_effects_p (XEXP (op1, 1)))
> +     return simplify_gen_binary (IOR, mode, XEXP (op0, 1), op1);
> +
>        tem = simplify_with_subreg_not (code, mode, op0, op1);
>        if (tem)
>       return tem;

Reply via email to