"Roger Sayle" <ro...@nextmovesoftware.com> writes: > diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c > index 28c2dc6..ccf5f6d 100644 > --- a/gcc/simplify-rtx.c > +++ b/gcc/simplify-rtx.c > @@ -3128,6 +3128,17 @@ simplify_binary_operation_1 (enum rtx_code code, > machine_mode mode, > mode); > } > > + /* Convert (xor (and A C) (and B C)) into (and (xor A B) C). */ > + if (GET_CODE (op0) == AND > + && GET_CODE (op1) == AND > + && rtx_equal_p (XEXP (op0, 1), XEXP (op1, 1)) > + && ! side_effects_p (XEXP (op0, 1))) > + return simplify_gen_binary (AND, mode, > + simplify_gen_binary (XOR, mode, > + XEXP (op0, 0), > + XEXP (op1, 0)), > + XEXP (op0, 1)); > + > /* Convert (xor (and A B) B) to (and (not A) B). The latter may > correspond to a machine insn or result in further simplifications > if B is a constant. */
Looks good, but I guess we might as well add the corresponding (ior (and …) (and …)) and (and (and …) (and …)) rules at the same time. E.g. maybe have a new subfunction for logical ops that is shared by all of AND, IOR and XOR. In the case of AND, this ought to have precedence over simplify_associative_operation. No separate testcase is fine, but maybe it'd be worth adding some selftests to simplify_rtx_c_tests. Hope this isn't the best being the enemy of the good… Thanks, Richard