This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH] Prefer reg as first operand in commutative operator
On 14/02/12 13:46, Paolo Bonzini wrote:
On 02/14/2012 10:52 AM, Jakub Jelinek wrote:
> /* Complex expressions should be the first, so decrease priority
> of objects. Prefer pointer objects over non pointer objects. */
> - if ((REG_P (op) && REG_POINTER (op))
> - || (MEM_P (op) && MEM_POINTER (op)))
> - return -1;
> - return -2;
> + if(REG_P(op))
> + return -1;
> + else if ((REG_P (op) && REG_POINTER (op))
> + || (MEM_P (op) && MEM_POINTER (op)))
> + return -2;
> + return -3;
The above is definitely wrong, I think it will penalize e.g. Power6/7
Even if this was fixed, I'm not sure it is always the correct thing to
do, because it would override swap_commutative_operands_with_target. If
the target is memory, you'd want the memory to come first.
I was unaware of swap_commutative_operands_with_target, therefore the
patch change makes things a lot trickier.
In other words, there is no right answer as to whether REG or MEM should
I think the register allocator will generate good code using % if you
make your predicate nonimmediate_operand in operand 1:
[(set (match_operand:QI 0 "register_operand" "=c")
(ior:QI (match_operand:QI 1 "nonimmediate_operand" "%0")
(match_operand:QI 2 "general_operand" "cwmi")))
(clobber (reg:CC RCC))]
"register_operand(operands, QImode) ||
Yes, I think in general that seems to be the right procedure. In my
case, unfortunately it does not work.
The reason is that it allows:
(set (reg:QI ...)
(ior:QI (mem:QI (reg:QI ...))
(mem:QI (reg:QI ...))))
This wouldn't in general be a problem except that my backend only has
one register that can be used for a memory dereference, which means that
BASE_REG_CLASS is a class with a single register.
This seriously breaks IRA, which doesn't have two registers to allocate
for that rule.
I always try to change my backend before changing my port of GCC and
unfortunately in this case I saw no alternative my to change
commutative_operand_precedence. It might be the wrong solution in the
general case, therefore just disregard it.
Thanks for the comments,