Bug 30289

Summary: avr-gcc: builtin memset(): wrong code
Product: gcc Reporter: Dmitry K. <dmixm>
Component: targetAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: eric.weddington, gcc-bugs
Priority: P3 Keywords: wrong-code
Version: 4.1.1   
Target Milestone: 4.1.3   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Dmitry K. 2006-12-25 04:55:33 UTC
Thanks to Tom <tdolata@...>.

Program:
    void * memset (void *buf, int val, unsigned int n);
    void foo (void)
    {
        memset ((char *)0x4000, 0, 0x4000);
    }
is compiled into wrong code, where pointer and counter use 1 register pair:
        ldi r30,lo8(16384)
        ldi r31,hi8(16384)
        st Z+,__zero_reg__
        sbiw r30,1
        brne .-6
Compiler: 4.1.1
Options: -W -Wall -Os -S

I have try a set of versions:
        avr-gcc 3.3.5  - OK, loop counter is separate register pair
        avr-gcc 3.4.4, 4.0.2, 4.1.1  - wrong code.

Possible, the reason is in absence of '&' in clobber statement 'avr.md':
   ...
   (use (match_operand:HI 1 "register_operand" "!w,d"))
   (use (match_operand:HI 2 "const_int_operand" "n,n"))
   (clobber (match_scratch:HI 3 "=0,0"))
   (clobber (match_scratch:HI 4 "=1,1"))]
   ...
Comment 1 Eric Weddington 2007-04-04 23:46:00 UTC
Confirmed on 4.1.1.

Please add wrong-code to Keyword list.
Comment 2 aesok 2007-04-07 23:00:43 UTC
Subject: Bug 30289

Author: aesok
Date: Sat Apr  7 23:00:33 2007
New Revision: 123647

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123647
Log:
	PR target/30289
	* config/avr/avr.md (*clrmemqi, *clrmemhi): Mark operand 4 as 
	earlyclobber.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/avr/avr.md

Comment 3 aesok 2007-04-07 23:15:00 UTC
Subject: Bug 30289

Author: aesok
Date: Sat Apr  7 23:14:51 2007
New Revision: 123648

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123648
Log:
	PR target/30289
	* config/avr/avr.md (*clrmemqi, *clrmemhi): Mark operand 4 as 
	earlyclobber.

Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/config/avr/avr.md

Comment 4 aesok 2007-04-07 23:21:11 UTC
Subject: Bug 30289

Author: aesok
Date: Sat Apr  7 23:21:01 2007
New Revision: 123649

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123649
Log:
	PR target/30289
	* config/avr/avr.md (*clrmemqi, *clrmemhi): Mark operand 4 as 
	earlyclobber.


Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/config/avr/avr.md

Comment 5 aesok 2007-04-07 23:23:28 UTC
Fixed in 4.1, 4.2 branch, and HEAD. 
Comment 6 Eric Weddington 2007-04-09 04:01:21 UTC
Correcting target milestone to 4.1.3.