public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/42500]  New: unnecessary register move
@ 2009-12-25 12:47 carrot at google dot com
  2009-12-30  0:08 ` [Bug target/42500] " ramana at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: carrot at google dot com @ 2009-12-25 12:47 UTC (permalink / raw)
  To: gcc-bugs

Compile the following code with options -O2

extern "C" void foo(int a[4]);
extern "C" void bar(int a, int b, int c, int d)
{
    int v[4] = {a,b,c,d};
     foo(v);
     foo(v);
}


GCC generates

bar:
        stmfd   sp!, {r4, lr}
        .save {r4, lr}
.LCFI0:
        .pad #16
        sub     sp, sp, #16
.LCFI1:
        mov     lr, #0
        add     ip, sp, #8
        str     lr, [ip], #4
        str     r0, [sp, #0]
        mov     r0, sp
        str     lr, [ip, #0]
        stmib   sp, {r1, r2, r3}        @ phole stm
        bl      foo
        mov     r0, sp
        mov     r4, sp             // A
        bl      foo
        add     sp, sp, #16
        ldmfd   sp!, {r4, lr}
        bx      lr

Instruction A move sp to r4, but r4 is never used again.

If compile the code with options -Os, the result is even worse:

bar:
        stmfd   sp!, {r0, r1, r2, r3, r4, r5, r6, r7, r8, lr}
        .save {r0, r1, r2, r3, r4, r5, r6, r7, r8, lr}
.LCFI0:
        mov     r6, r0
        mov     r5, r1
        mov     r4, r2
        mov     r1, #0
        mov     r2, #16
        mov     r0, sp
        mov     r8, r3
        bl      memset
        mov     r0, sp
        str     r6, [sp, #0]
        str     r5, [sp, #4]
        str     r4, [sp, #8]
        str     r8, [sp, #12]
        bl      foo
        mov     r0, sp
        mov     r7, sp
        bl      foo
        ldmfd   sp!, {r0, r1, r2, r3, r4, r5, r6, r7, r8, lr}
        bx      lr

It calls memset to set the array to 0, then store parameters to that array. It
is quite inefficient.


-- 
           Summary: unnecessary register move
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: carrot at google dot com
 GCC build triplet: i686-linux
  GCC host triplet: i686-linux
GCC target triplet: arm-eabi


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


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

* [Bug target/42500] unnecessary register move
  2009-12-25 12:47 [Bug target/42500] New: unnecessary register move carrot at google dot com
@ 2009-12-30  0:08 ` ramana at gcc dot gnu dot org
  2009-12-30  0:10 ` ramana at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ramana at gcc dot gnu dot org @ 2009-12-30  0:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from ramana at gcc dot gnu dot org  2009-12-30 00:08 -------
What architecture options are you using  ? With         .ident  "GCC: (GNU)
4.5.0 20091229 (experimental)" and -O2 I get the redundant move into r4 of sp . 

But for -Os I get the following very different code.  I don't see the call to
memset ever. 

        .text
        .align  2
        .global foo
        .type   foo, %function
foo:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        stmfd   sp!, {r0, r1, r2, lr}   @,
        mov     r3, r0  @ a, a
        ldr     r2, [r0, #12]   @ tmp142,
        str     r2, [sp, #0]    @ tmp142,
        ldr     r0, .L2 @,
        ldmia   r3, {r1, r2, r3}        @ phole ldm
        bl      printf  @
        ldmfd   sp!, {r1, r2, r3, pc}
.L3:
        .align  2
.L2:
        .word   .LC0
        .size   foo, .-foo
        .section        .rodata.str1.1,"aMS",%progbits,1
.LC0:
        .ascii  "%d %d %d %d \012\000"
        .ident  "GCC: (GNU) 4.5.0 20091229 (experimental)"
        .section        .note.GNU-stack,"",%progbits


-- 

ramana at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|unnecessary register move   |unnecessary register move


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


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

* [Bug target/42500] unnecessary register move
  2009-12-25 12:47 [Bug target/42500] New: unnecessary register move carrot at google dot com
  2009-12-30  0:08 ` [Bug target/42500] " ramana at gcc dot gnu dot org
@ 2009-12-30  0:10 ` ramana at gcc dot gnu dot org
  2009-12-30  6:46 ` carrot at google dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ramana at gcc dot gnu dot org @ 2009-12-30  0:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from ramana at gcc dot gnu dot org  2009-12-30 00:10 -------
(In reply to comment #1)
> What architecture options are you using  ? With         .ident  "GCC: (GNU)
> 4.5.0 20091229 (experimental)" and -O2 I get the redundant move into r4 of sp . 
> 
> But for -Os I get the following very different code.  I don't see the call to
> memset ever. \

Sorry I meant this rather than the code in comment #1

bar:
        @ args = 0, pretend = 0, frame = 16
        @ frame_needed = 0, uses_anonymous_args = 0
        stmfd   sp!, {r0, r1, r2, r3, r4, lr}
        str     r0, [sp, #0]
        mov     r0, sp
        stmib   sp, {r1, r2, r3}        @ phole stm
        bl      foo
        mov     r0, sp
        mov     r4, sp
        bl      foo
        ldmfd   sp!, {r0, r1, r2, r3, r4, pc}
        .size   bar, .-bar
        .ident  "GCC: (GNU) 4.5.0 20091229 (experimental)"
        .section        .note.GNU-stack,"",%progbits


-- 


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


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

* [Bug target/42500] unnecessary register move
  2009-12-25 12:47 [Bug target/42500] New: unnecessary register move carrot at google dot com
  2009-12-30  0:08 ` [Bug target/42500] " ramana at gcc dot gnu dot org
  2009-12-30  0:10 ` ramana at gcc dot gnu dot org
@ 2009-12-30  6:46 ` carrot at google dot com
  2009-12-30 19:15 ` [Bug c++/42500] Unnecessary call to memset to initialize array at Os ramana at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: carrot at google dot com @ 2009-12-30  6:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from carrot at google dot com  2009-12-30 06:46 -------
My complete command line:

"/home/carrot/compiler/armobj/gcc/cc1plus" "-fpreprocessed" "testH.ii" "-quiet"
"-dumpbase" "testH.cpp" "-auxbase-strip" "obj/./testH.o" "-Os" "-o" "testH.s"

Please compile it as C++ program. When I compiled it as C program, I got the
same result as yours.


-- 


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


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

* [Bug c++/42500] Unnecessary call to memset to initialize array at Os
  2009-12-25 12:47 [Bug target/42500] New: unnecessary register move carrot at google dot com
                   ` (2 preceding siblings ...)
  2009-12-30  6:46 ` carrot at google dot com
@ 2009-12-30 19:15 ` ramana at gcc dot gnu dot org
  2010-03-16 15:51 ` [Bug rtl-optimization/42500] Unnecessary mov of sp to a register bernds at codesourcery dot com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ramana at gcc dot gnu dot org @ 2009-12-30 19:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from ramana at gcc dot gnu dot org  2009-12-30 19:14 -------
Ok (In reply to comment #3)
> My complete command line:
> 
> "/home/carrot/compiler/armobj/gcc/cc1plus" "-fpreprocessed" "testH.ii" "-quiet"
> "-dumpbase" "testH.cpp" "-auxbase-strip" "obj/./testH.o" "-Os" "-o" "testH.s"
> 
> Please compile it as C++ program. When I compiled it as C program, I got the
> same result as yours.

Ok that is a subject of a separate bug report that has been filed at PR42556.
Let this remain about just the redundant move of sp into r4.

Ramana


-- 

ramana at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
          Component|target                      |c++
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-12-30 19:14:49
               date|                            |
            Summary|unnecessary register move   |Unnecessary call to memset
                   |                            |to initialize array at Os


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


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

* [Bug rtl-optimization/42500] Unnecessary mov of sp to a register
  2009-12-25 12:47 [Bug target/42500] New: unnecessary register move carrot at google dot com
                   ` (3 preceding siblings ...)
  2009-12-30 19:15 ` [Bug c++/42500] Unnecessary call to memset to initialize array at Os ramana at gcc dot gnu dot org
@ 2010-03-16 15:51 ` bernds at codesourcery dot com
  2010-06-04 12:44 ` bernds at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: bernds at codesourcery dot com @ 2010-03-16 15:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from bernds at codesourcery dot com  2010-03-16 15:51 -------
I believe this is exactly the same problem as PR40615.


-- 


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


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

* [Bug rtl-optimization/42500] Unnecessary mov of sp to a register
  2009-12-25 12:47 [Bug target/42500] New: unnecessary register move carrot at google dot com
                   ` (4 preceding siblings ...)
  2010-03-16 15:51 ` [Bug rtl-optimization/42500] Unnecessary mov of sp to a register bernds at codesourcery dot com
@ 2010-06-04 12:44 ` bernds at gcc dot gnu dot org
  2010-06-07 22:46 ` bernds at gcc dot gnu dot org
  2010-06-08 15:31 ` hjl dot tools at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: bernds at gcc dot gnu dot org @ 2010-06-04 12:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from bernds at gcc dot gnu dot org  2010-06-04 12:44 -------
Subject: Bug 42500

Author: bernds
Date: Fri Jun  4 12:44:01 2010
New Revision: 160260

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160260
Log:
        PR rtl-optimization/39871
        PR rtl-optimization/40615
        PR rtl-optimization/42500
        PR rtl-optimization/42502
        * ira.c (init_reg_equiv_memory_loc: New function.
        (ira): Call it twice.
        * reload.h (calculate_elim_costs_all_insns): Declare.
        * ira-costs.c: Include "reload.h".
        (regno_equiv_gains): New static variable.
        (init_costs): Allocate it.
        (finish_costs): Free it.
        (ira_costs): Call calculate_elim_costs_all_insns.
        (find_costs_and_classes): Take estimated elimination costs
        into account.
        (ira_adjust_equiv_reg_cost): New function.
        * ira.h (ira_adjust_equiv_reg_cost): Declare it.
        * reload1.c (init_eliminable_invariants, free_reg_equiv,
        elimination_costs_in_insn, note_reg_elim_costly): New static
        functions.
        (elim_bb): New static variable.
        (reload): Move code out of here into init_eliminable_invariants and
        free_reg_equiv.  Call them.
        (calculate_elim_costs_all_insns): New function.
        (eliminate_regs_1): Declare.  Add extra arg FOR_COSTS;
        all callers changed.  If FOR_COSTS is true, don't call alter_reg,
        but call note_reg_elim_costly if we turned a valid memory address
        into an invalid one.
        * Makefile.in (ira-costs.o): Depend on reload.h.

testsuite/
        PR rtl-optimization/39871
        PR rtl-optimization/40615
        PR rtl-optimization/42500
        PR rtl-optimization/42502
        * gcc.target/arm/eliminate.c: New test.


Added:
    trunk/gcc/testsuite/gcc.target/arm/eliminate.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/Makefile.in
    trunk/gcc/ira-costs.c
    trunk/gcc/ira.c
    trunk/gcc/ira.h
    trunk/gcc/reload.h
    trunk/gcc/reload1.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug rtl-optimization/42500] Unnecessary mov of sp to a register
  2009-12-25 12:47 [Bug target/42500] New: unnecessary register move carrot at google dot com
                   ` (5 preceding siblings ...)
  2010-06-04 12:44 ` bernds at gcc dot gnu dot org
@ 2010-06-07 22:46 ` bernds at gcc dot gnu dot org
  2010-06-08 15:31 ` hjl dot tools at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: bernds at gcc dot gnu dot org @ 2010-06-07 22:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from bernds at gcc dot gnu dot org  2010-06-07 22:46 -------
Fixed.


-- 

bernds at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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


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

* [Bug rtl-optimization/42500] Unnecessary mov of sp to a register
  2009-12-25 12:47 [Bug target/42500] New: unnecessary register move carrot at google dot com
                   ` (6 preceding siblings ...)
  2010-06-07 22:46 ` bernds at gcc dot gnu dot org
@ 2010-06-08 15:31 ` hjl dot tools at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: hjl dot tools at gmail dot com @ 2010-06-08 15:31 UTC (permalink / raw)
  To: gcc-bugs



-- 

hjl dot tools at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.6.0


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


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

end of thread, other threads:[~2010-06-08 15:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-25 12:47 [Bug target/42500] New: unnecessary register move carrot at google dot com
2009-12-30  0:08 ` [Bug target/42500] " ramana at gcc dot gnu dot org
2009-12-30  0:10 ` ramana at gcc dot gnu dot org
2009-12-30  6:46 ` carrot at google dot com
2009-12-30 19:15 ` [Bug c++/42500] Unnecessary call to memset to initialize array at Os ramana at gcc dot gnu dot org
2010-03-16 15:51 ` [Bug rtl-optimization/42500] Unnecessary mov of sp to a register bernds at codesourcery dot com
2010-06-04 12:44 ` bernds at gcc dot gnu dot org
2010-06-07 22:46 ` bernds at gcc dot gnu dot org
2010-06-08 15:31 ` hjl dot tools at gmail dot com

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).