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. > > gcc/ChangeLog: > > * simplify-rtx.cc (simplify_context::simplify_binary_operation_1): > Handle > more logical simplifications. > > --- > gcc/simplify-rtx.cc | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc > index b34fd2f4b9e..daa46054f83 100644 > --- a/gcc/simplify-rtx.cc > +++ b/gcc/simplify-rtx.cc > @@ -4063,6 +4063,19 @@ 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))
GCC RTL doesn't use commas :) > + into B | (1 << A). */ > + if (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)) I think you also need to check !side_effects_p on XEXP (op1, 1), since we'll be dropping one instance of the expression. > + && rtx_equal_p (XEXP (op0, 1), XEXP (op0, 1))) Is this last line a typo? It should always be true. I suppose the main question is whether we can safely apply this for !SHIFT_COUNT_TRUNCATED targets. Thanks, Richard > + return simplify_gen_binary (IOR, mode, XEXP (op0, 1), op1); > + > tem = simplify_with_subreg_not (code, mode, op0, op1); > if (tem) > return tem;