This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
postreload problem using reload_inm and SECONDARY_RELOAD macros
- From: BELBACHIR Selim <selim dot belbachir at fr dot thalesgroup dot com>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Wed, 14 Sep 2011 15:09:35 +0200
- Subject: postreload problem using reload_inm and SECONDARY_RELOAD macros
Hi,
I'm writing a backend for gcc3.4.6 and I'm a bit confused about reload passes.
-> my constraints :
'b' = arithmetic/logical unit register ($R, class R_REGS)
'c' = counter register ($C, class C_REGS)
'v' = memory with several special constraint (also described in predicate my_mem_or_reg_operand)
-> movsi expand/insn :
?(define_insn "movsi_internal"
? [(set ??
??????(match_operand:SI 0 "my_mem_or_reg_operand" "=v,v,c,b,b ")
??????(match_operand: SI 1 "general_operand" "c,b,v,v,i "))]
??""
??"@
??mov %1,%0
??[.]
??loadi %1,%0"
)
?(define_expand "movsi"
? [(set ??
??????(match_operand:SI 0 "general_operand" "")
??????(match_operand:SI 1 "general_operand" ""))]
??""
??{
?????/* Handle Memory to Memory and immediate to memory movs */
???? if (((GET_CODE (operands[1]) == MEM) || immediate_operand (operands[1], SImode))
&& (GET_CODE(operands[0])== MEM) )
?????{
????? ??operands[1] = force_reg(SImode,operands[1]);
?????}
??}
)
Note there is no instruction to move immediate to $R regs ('b' constraint) but there is one to move immediate to $C regs ('c' constraint).
I have no mean to express this limitation inside predicates (because pseudo register don't known in which hard register they will be allocated), reload pass create some moves from immediate to $R.? :
arithmetic.c:197: error: insn does not satisfy its constraints:
(insn 1505 903 1506 0 (set (reg:SI 25 $R9)
??????? (const_int 8 [0x8])) 0 {movsi_internal} (nil)
??? (nil))
arithmetic.c:197: internal compiler error: in reload_cse_simplify_operands, at postreload.c:391
So, I read the doc :) and figured out how to control the reload pass. I added 2 MACROs and the reload_insi expand :
#define PREFERRED_RELOAD_CLASS(X,CLASS) my_preferred_reload_class(X,CLASS)
#define SECONDARY_INPUT_RELOAD_CLASS(CLASS, MODE, X) my_secondary_input_reload_class (CLASS, MODE, X)
enum reg_class my_preferred_reload_class(rtx x, enum reg_class rclass)
{
?? if (GET_CODE(x) == CONST_INT || GET_CODE(x) == CONST_DOUBLE) {
???????if (rclass == GENERAL_REGS) {
??????????return C_REGS;
???????}
???????else if (rclass == R_REGS) {
??????????return NO_REGS; /* put the constant in memory */
???????}
?? }
?? return rclass;
}
enum reg_class my_secondary_input_reload_class(enum reg_class rclass, enum machine_mode mode, rtx x)
{
??if ((GET_CODE(x) == CONST_INT || GET_CODE(x) == CONST_DOUBLE) && rclass == R_REGS) {
?????return C_REGS; /* use C_REGS for clobber in reload_insi */
??}
??return NO_REGS;
}
(define_expand "reload_insi"
? [(set
???? (match_operand:SI 0 "register_operand" "=b")
??? ?(match_operand:SI 1 "immediate_operand" "i"))
? (clobber (match_operand:SI 2 "register_operand" "=c"))]
????"
????{???????????
???????emit_insn(gen_rtx_SET(SImode, operands[2], operands[1]));
???????emit_insn(gen_rtx_SET(SImode, operands[0], operands[2]));
?????? DONE;
????}
)
Theses MACROs and insn do not solve my problem and the forbidden move keeps on being emitted.
Did I misunderstood something ? A my doing something illegal ? Should I do things differently?
(A printf in my reload_insi shows that this expand is never called.)
??????????????? Thank you for your help.