Help with constraint for single register

Robert Baruch autophile@gmail.com
Tue Dec 28 20:58:00 GMT 2004


On Tue, 28 Dec 2004 13:01:06 -0500, Robert Baruch <autophile@gmail.com> wrote:
> 
> I've traced where this change occurs to the GCSE phase.
> try_replace_reg (gcse.c:3876) is called when a potential replacement
> is found, in this case replacing W in insn 2620 with pseudo-59.
> Basically what happens in try_replace_reg is that the instruction is
> changed, and the old instruction is saved. Then the change is
> validated in apply_change_group (recog.c:318). That will determine if
> the changed instruction is invalid, by calling insn_invalid_p
> (recog.c:259). That, in turn, calls the generated recog function in
> insn-recog.c... which only goes with the define_expand of movqi, and
> does not call the expander's body code.
> 
> Since I defined the movqi expander to accept anything in general
> (because the RTL generation phase needs a movqi pattern that accepts
> anything), and to generate code in its body which uses W to do the
> actual move, insn_invalid_p determines that the instruction is OK
> (because it satisfies the generalized expander).

This is interesting... I added a condition to my *movqi insn,
requiring that one of the operands be the W register:

(define_insn "*movqi"
	[(set (match_operand:QI 0 "nonimmediate_operand" "=r,m,w,W,W")
		  (match_operand:QI 1 "general_operand" "W,W,w,i,r"))]
  "(pic_is_w_reg(operands[0]) || pic_is_w_reg(operands[1]))"
  "\tmovf %1,%0"
  [(set_attr "cc" "z")]
  )

Before, the condition was empty.

With only that single change, the GCSE phase now does not replace W,
because apparently the recog() function in insn-recog.c is generated
from the define_insn, not the define_expand as I had thought
previously. With this change, the replacement of W in the insn is
ruled invalid, and the change is not made.

So we're back to what I had originally thought, which is that the
expander is used only during the RTL generation phase. However, the
recog function apparently does not check the constraints, but only the
predicates and the condition.

So I'm very confused now -- there are three restrictions in a
define_insn: predicate, constraint, and condition. Only the predicate
and condition are used in recog(). I'm not quite sure which are used
when :(

--Rob



More information about the Gcc mailing list