public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/59609] New: LRA generates bad code for libgcc function udivmoddi4 on thumb1 target
@ 2013-12-27  5:49 terry.guo at arm dot com
  2013-12-27  5:58 ` [Bug target/59609] [4.9 Regression] " terry.guo at arm dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: terry.guo at arm dot com @ 2013-12-27  5:49 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/59609] [4.9 Regression] LRA generates bad code for libgcc function udivmoddi4 on thumb1 target
  2013-12-27  5:49 [Bug c/59609] New: LRA generates bad code for libgcc function udivmoddi4 on thumb1 target terry.guo at arm dot com
@ 2013-12-27  5:58 ` terry.guo at arm dot com
  2013-12-27  5:58 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: terry.guo at arm dot com @ 2013-12-27  5:58 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59609

--- Comment #1 from Terry Guo <terry.guo at arm dot com> ---
Here are some investigations. In the dump of IRA pass, we have jump insn like:

(jump_insn 31 24 172 5 (parallel [
            (set (pc)
                (if_then_else (lt (plus:SI (reg/v:SI 119 [ i ])
                            (const_int -32 [0xffffffffffffffe0]))
                        (const_int 0 [0]))
                    (label_ref 35)
                    (pc)))
            (set (reg:SI 181)
                (plus:SI (reg/v:SI 119 [ i ])
                    (const_int -32 [0xffffffffffffffe0])))
            (clobber (scratch:SI))
        ]) myudi.c:13 225 {*addsi3_cbranch}
     (int_list:REG_BR_PROB 2100 (nil))
 -> 35)

Next in the dump of reload pass, it is turned into:

(jump_insn 31 254 255 5 (parallel [
            (set (pc)
                (if_then_else (lt (plus:SI (reg:SI 3 r3 [181])
                            (const_int -32 [0xffffffffffffffe0]))
                        (const_int 0 [0]))
                    (label_ref 35)
                    (pc)))
            (set (reg:SI 3 r3 [181])
                (plus:SI (reg:SI 3 r3 [181])
                    (const_int -32 [0xffffffffffffffe0])))
            (clobber (scratch:SI))
        ]) myudi.c:13 225 {*addsi3_cbranch}
     (int_list:REG_BR_PROB 2100 (nil))
 -> 35)
(insn 255 31 172 5 (set (reg:SI 12 ip [181])
        (reg:SI 3 r3 [181])) myudi.c:13 197 {*thumb1_movsi_insn}
     (nil))

The subsequent passes will change the position of insn 255 and cause ip
uninitialized when do jump.

When disable LRA, in reload pass the jump_insn 31 will be turned into something
like:

(jump_insn 31 255 172 5 (parallel [
            (set (pc)
                (if_then_else (lt (plus:SI (reg:SI 0 r0)
                            (const_int -32 [0xffffffffffffffe0]))
                        (const_int 0 [0]))
                    (label_ref 35)
                    (pc)))
            (set (reg:SI 12 ip [181])
                (plus:SI (reg:SI 0 r0)
                    (const_int -32 [0xffffffffffffffe0])))
            (clobber (reg:SI 0 r0))
        ]) myudi.c:13 225 {*addsi3_cbranch}
     (int_list:REG_BR_PROB 2100 (nil))
 -> 35)

This is good and will produce correct code.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/59609] [4.9 Regression] LRA generates bad code for libgcc function udivmoddi4 on thumb1 target
  2013-12-27  5:49 [Bug c/59609] New: LRA generates bad code for libgcc function udivmoddi4 on thumb1 target terry.guo at arm dot com
  2013-12-27  5:58 ` [Bug target/59609] [4.9 Regression] " terry.guo at arm dot com
@ 2013-12-27  5:58 ` pinskia at gcc dot gnu.org
  2013-12-27  6:06 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-12-27  5:58 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59609

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unknown                     |4.9.0
   Target Milestone|---                         |4.9.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/59609] [4.9 Regression] LRA generates bad code for libgcc function udivmoddi4 on thumb1 target
  2013-12-27  5:49 [Bug c/59609] New: LRA generates bad code for libgcc function udivmoddi4 on thumb1 target terry.guo at arm dot com
  2013-12-27  5:58 ` [Bug target/59609] [4.9 Regression] " terry.guo at arm dot com
  2013-12-27  5:58 ` pinskia at gcc dot gnu.org
@ 2013-12-27  6:06 ` pinskia at gcc dot gnu.org
  2014-01-03 16:45 ` rearnsha at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-12-27  6:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59609

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Terry Guo from comment #1)
> Here are some investigations. In the dump of IRA pass, we have jump insn
> like:

And this is why the old saying of reload not cannot reload a jump instruction
comes true.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug target/59609] [4.9 Regression] LRA generates bad code for libgcc function udivmoddi4 on thumb1 target
  2013-12-27  5:49 [Bug c/59609] New: LRA generates bad code for libgcc function udivmoddi4 on thumb1 target terry.guo at arm dot com
                   ` (2 preceding siblings ...)
  2013-12-27  6:06 ` pinskia at gcc dot gnu.org
@ 2014-01-03 16:45 ` rearnsha at gcc dot gnu.org
  2014-01-16 19:14 ` [Bug middle-end/59609] " vmakarov at gcc dot gnu.org
  2014-01-16 19:42 ` jakub at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rearnsha at gcc dot gnu.org @ 2014-01-03 16:45 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59609

Richard Earnshaw <rearnsha at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vmakarov at redhat dot com

--- Comment #3 from Richard Earnshaw <rearnsha at gcc dot gnu.org> ---
The patterns were carefully written to handle all the needed output-reload
situations.  I don't know why LRA doesn't make use of them.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug middle-end/59609] [4.9 Regression] LRA generates bad code for libgcc function udivmoddi4 on thumb1 target
  2013-12-27  5:49 [Bug c/59609] New: LRA generates bad code for libgcc function udivmoddi4 on thumb1 target terry.guo at arm dot com
                   ` (3 preceding siblings ...)
  2014-01-03 16:45 ` rearnsha at gcc dot gnu.org
@ 2014-01-16 19:14 ` vmakarov at gcc dot gnu.org
  2014-01-16 19:42 ` jakub at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: vmakarov at gcc dot gnu.org @ 2014-01-16 19:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59609

--- Comment #5 from Vladimir Makarov <vmakarov at gcc dot gnu.org> ---
Author: vmakarov
Date: Thu Jan 16 19:13:54 2014
New Revision: 206677

URL: http://gcc.gnu.org/viewcvs?rev=206677&root=gcc&view=rev
Log:
2014-01-16  Vladimir Makarov  <vmakarov@redhat.com>

    PR middle-end/59609
    * lra-constraints.c (process_alt_operands): Add printing debug
    info.  Check absence of input/output reloads for matched operands
    too.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/lra-constraints.c


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug middle-end/59609] [4.9 Regression] LRA generates bad code for libgcc function udivmoddi4 on thumb1 target
  2013-12-27  5:49 [Bug c/59609] New: LRA generates bad code for libgcc function udivmoddi4 on thumb1 target terry.guo at arm dot com
                   ` (4 preceding siblings ...)
  2014-01-16 19:14 ` [Bug middle-end/59609] " vmakarov at gcc dot gnu.org
@ 2014-01-16 19:42 ` jakub at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-01-16 19:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59609

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|---                         |FIXED

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Hopefully fixed.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-01-16 19:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-27  5:49 [Bug c/59609] New: LRA generates bad code for libgcc function udivmoddi4 on thumb1 target terry.guo at arm dot com
2013-12-27  5:58 ` [Bug target/59609] [4.9 Regression] " terry.guo at arm dot com
2013-12-27  5:58 ` pinskia at gcc dot gnu.org
2013-12-27  6:06 ` pinskia at gcc dot gnu.org
2014-01-03 16:45 ` rearnsha at gcc dot gnu.org
2014-01-16 19:14 ` [Bug middle-end/59609] " vmakarov at gcc dot gnu.org
2014-01-16 19:42 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).