avr-gcc 4.6.1 -Os -mmcu=atmega8 translates the following test function int madd_x (int i, char a, char b) { return i + a*b; } to muls r22,r20 ; 10 mulqihi3 movw r20,r0 clr r1 add r20,r24 ; 11 *addhi3/1 adc r21,r25 movw r24,r20 ; 31 *movhi/1 where it could be muls r22,r20 ; *maddqihi4/1 add r24,r0 adc r25,r1 clr r1 instead i.e. the addition can be done in place and the product need not to be moved out of R0, reducing code size and register pressure and increasing speed.
Created attachment 25241 [details] madd.c Just some test cases.
Created attachment 25251 [details] madd.c
Author: gjl Date: Tue Sep 13 09:23:36 2011 New Revision: 178806 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178806 Log: PR target/50358 * config/avr/predicates.md (const_1_to_6_operand): New predicate. * config/avr/avr.md: (extend_s): New code attribute. (mul_r_d): New code attribute. (*maddqihi4, *umaddqihi4): New insns. (*msubqihi4, *umsubqihi4): New insns. (*usmaddqihi4, *sumaddqihi4): New insns. (*usmsubqihi4, *susubdqihi4): New insns. (*umaddqihi4.uconst, *maddqihi4.sconst): New insn-and-splits. (*umsubqihi4.uconst, *msubqihi4.sconst): New insn-and-splits. (*umsubqihi4.uconst.ashift): New insn-and-split. (*msubqihi4.sconst.ashift): New insn-and-split. (*sumaddqihi4.uconst): New insn-and-split. (*sumsubqihi4.uconst): New insn-and-split. * config/avr/avr.c (avr_rtx_costs): Report costs of above in case PLUS:HI and MINUS:HI. Modified: trunk/gcc/ChangeLog trunk/gcc/config/avr/avr.c trunk/gcc/config/avr/avr.md trunk/gcc/config/avr/predicates.md
Author: gjl Date: Fri Sep 16 18:27:10 2011 New Revision: 178912 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178912 Log: PR target/50358 * config/avr/avr.md (*ashiftqihi2.signx.1): New insn. (*maddqi4, *maddqi4.const): New insns. (*msubqi4, *msubqi4.const): New insns. * config/avr/avr.c (avr_rtx_costs): Record costs of above in cases PLUS:QI and MINUS:QI. Increase costs of multiply-add/-sub for HImode by 1 in the case of multiplying with a CONST_INT. Record cost of *ashiftqihi2.signx.1 in case ASHIFT:QI. Modified: trunk/gcc/ChangeLog trunk/gcc/config/avr/avr.c trunk/gcc/config/avr/avr.md
Resolved for 4.7.0 milestone.