For insns like the following a scratch register is needed: (set (reg:SI 46 [ *p_2(D) ]) (mem:SI (reg/v/f:HI 44 [ p ]) [2 *p_2(D)+0 S4 A8 AS2])) {*movsi} targetm.secondary_reload is called as expected with in_p = true (input reload) x = (mem:SI (reg/v/f:HI 44 [ p ]) [2 *p_2(D)+0 S4 A8 AS2]) reload_mode = SImode The target hook returns NO_REGS because the load can be performed directly into any register class, but requires a QI scratch register. Thus, the hook sets sri->icode to an insn that adds a scratch register: (define_insn "reloadin_as_si" [(parallel [(match_operand:SI 0 "register_operand" "=r") (match_operand:SI 1 "memory_operand" "m") (match_operand:QI 2 "register_operand" "=d")])] "" ...) Outcome is that this insn is never used and IRA still uses *movsi insn which is wrong. Please can someone explain what I am doing wrong and point me to the documentation or examples? I read http://gcc.gnu.org/onlinedocs/gccint/Register-Classes.html#index-TARGET_005fSECONDARY_005fRELOAD-4051 but could not find anything why sri->icode is ignored. FYI, the hook is called 4 times, always with the following backtrace: #0 avr_secondary_reload (in_p=true, x=0xb7b40fb4, reload_class=12, mode=SImode, sri=0xbfffd5c8) at ../../../gcc.gnu.org/trunk/gcc/config/avr/avr.c:1873 #1 0x0849631d in copy_cost (x=0xb7b40fb4, mode=SImode, rclass=12, to_p=true, prev_sri=0x0) at ../../../gcc.gnu.org/trunk/gcc/ira-costs.c:344 #2 0x08498222 in record_reg_classes (n_alts=6, n_ops=2, ops=0x8bb73c0, modes=0xbfffd958, constraints=0xbfffd9d0, insn=0xb7b9d4a4, pref=0x0) at ../../../gcc.gnu.org/trunk/gcc/ira-costs.c:862 #3 0x08498c72 in record_operand_costs (insn=0xb7b9d4a4, pref=0x0) at ../../../gcc.gnu.org/trunk/gcc/ira-costs.c:1257 #4 0x08498f98 in scan_one_insn (insn=0xb7b9d4a4) at ../../../gcc.gnu.org/trunk/gcc/ira-costs.c:1320 #5 0x084991fa in process_bb_for_costs (bb=0xb7bcb140) at ../../../gcc.gnu.org/trunk/gcc/ira-costs.c:1453 #6 0x0849923d in process_bb_node_for_costs (loop_tree_node=0x8c305d0) at ../../../gcc.gnu.org/trunk/gcc/ira-costs.c:1465 #7 0x0848e7dc in ira_traverse_loop_tree (bb_p=true, loop_node=0x8c30650, preorder_func=0x849921e <process_bb_node_for_costs>, postorder_func=0) at ../../../gcc.gnu.org/trunk/gcc/ira-build.c:1492 #8 0x0849990b in find_costs_and_classes (dump_file=0x0) at ../../../gcc.gnu.org/trunk/gcc/ira-costs.c:1550 #9 0x0849a568 in ira_costs () at ../../../gcc.gnu.org/trunk/gcc/ira-costs.c:2044 #10 0x08494510 in ira_build () at ../../../gcc.gnu.org/trunk/gcc/ira-build.c:3091 #11 0x0848a890 in ira (f=0x0) at ../../../gcc.gnu.org/trunk/gcc/ira.c:4223 #12 0x0848aac4 in rest_of_handle_ira () at ../../../gcc.gnu.org/trunk/gcc/ira.c:4393 #13 0x08515412 in execute_one_pass (pass=0x8b9d560) at ../../../gcc.gnu.org/trunk/gcc/passes.c:2199 ... Thanks