From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22026 invoked by alias); 27 Dec 2013 05:49:47 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 21998 invoked by uid 48); 27 Dec 2013 05:49:42 -0000 From: "terry.guo at arm dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/59609] New: LRA generates bad code for libgcc function udivmoddi4 on thumb1 target Date: Fri, 27 Dec 2013 05:49:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: blocker X-Bugzilla-Who: terry.guo at arm dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-12/txt/msg02243.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59609 Bug ID: 59609 Summary: LRA generates bad code for libgcc function udivmoddi4 on thumb1 target Product: gcc Version: unknown Status: UNCONFIRMED Severity: blocker Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: terry.guo at arm dot com Created attachment 31523 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31523&action=edit a reduced case Thumb-1 target like cortex-m0 hasn't hardware div instruction, thus the function __udivmoddi4 in libgcc is used. However this function is wrongly compiled by LRA which is enabled in recent gcc, codes that use __udivmoddi4 will get a wrong results. When print unsigned long long value using printf function, the printf function will use __udivmoddi4 and eventually will end up with dead loop. Attachment is a reduced case based on __udivmoddi4 function.And I am using the latest gcc trunk code. Compile the attached case with command: arm-none-eabi-gcc -mthumb -mcpu=cortex-m0 -O2 -S myudi.c then check the assembly code: sub r3, r3, #32 << should initialize ip after this insn bpl .LCB31 b .L4 @long jump .LCB31: mov ip, r3 mov r3, r9 mov r2, ip lsl r3, r3, r2 mov r7, r3 .L5: mov r3, r9 lsl r3, r3, r1 mov r6, r3 cmp r7, r5 bhi .L20 beq .L29 .L22: mov r3, ip << Here is the wrong code, the ip is uninitialized. sub r4, r4, r6 sbc r5, r5, r7 cmp r3, #0 bge .LCB50