On Tue, Dec 19, 2023 at 12:48:46AM +0800, Xi Ruoyao wrote: > > > gcc/ChangeLog: > > > > > > PR middle-end/113033 > > > * expmed.cc (expand_shift_1): When expanding rotate shift, call > > > negate_rtx instead of simplify_gen_unary (NEG, ...). > > > The key difference being that using negate_rtx will go through the > > expander which knows how to synthesize negation whereas > > simplify_gen_unary will just generate a (neg ...) and assume it matches > > something in the backend, right? > > For PR113033 the key difference (to me) is negate_rtx emits an insn to > set a new pseudo reg to -x. So the result will be > > (set (reg:SI 81) (neg:SI (reg:SI 80))) > > then > > (and (reg:SI 81) (const_int 31)) > > instead of a consolidated > > (and:SI (neg:SI (reg:SI IN)) (const_int 63)) > > AFAIK no backends have an instruction doing "negate an operand then and > bitwisely".
Can you explain why it doesn't work as is though? I mean, expand_shift_1 with that (and (neg (reg ...)) (const_int ...)) should try to legitimize the operand (e.g. in maybe_legitimize_operand -> force_operand and force_operand should be able to deal with that, AND is binary op, so it recurses on the 2 operands and NEG is UNARY_P, so the recursion should deal with that if it is not general_operand. Jakub