Bug 50358 - AVR: Implement [u]maddqihi4 [u]msubqihi4 patterns on the enhanced core
Summary: AVR: Implement [u]maddqihi4 [u]msubqihi4 patterns on the enhanced core
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.6.1
: P4 enhancement
Target Milestone: 4.7.0
Assignee: Georg-Johann Lay
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2011-09-11 17:44 UTC by Georg-Johann Lay
Modified: 2011-09-16 18:33 UTC (History)
1 user (show)

See Also:
Host:
Target: avr
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-09-11 00:00:00


Attachments
madd.c (252 bytes, text/plain)
2011-09-11 17:46 UTC, Georg-Johann Lay
Details
madd.c (412 bytes, text/plain)
2011-09-12 19:16 UTC, Georg-Johann Lay
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Georg-Johann Lay 2011-09-11 17:44:38 UTC
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.
Comment 1 Georg-Johann Lay 2011-09-11 17:46:14 UTC
Created attachment 25241 [details]
madd.c

Just some test cases.
Comment 2 Georg-Johann Lay 2011-09-12 19:16:00 UTC
Created attachment 25251 [details]
madd.c
Comment 3 Georg-Johann Lay 2011-09-13 09:23:40 UTC
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
Comment 4 Georg-Johann Lay 2011-09-16 18:27:16 UTC
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
Comment 5 Georg-Johann Lay 2011-09-16 18:33:59 UTC
Resolved for 4.7.0 milestone.