public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/40615]  New: unnecessary CSE
@ 2009-07-02  7:39 carrot at google dot com
  2009-07-02  7:39 ` [Bug target/40615] " carrot at google dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: carrot at google dot com @ 2009-07-02  7:39 UTC (permalink / raw)
  To: gcc-bugs

Compile the attached source code with options -march=armv5te -mthumb -Os
-fno-exceptions, gcc generates:

        push    {r4, lr}
        sub     sp, sp, #8
        add     r4, sp, #4    // redundant
        mov     r0, r4        // add  r0, sp, 4
        bl      _ZN1XC1Ev
        mov     r0, r4        // add  r0, sp, 4
        bl      _Z3barP1X
        mov     r0, r4        // add  r0, sp, 4
        bl      _ZN1XD1Ev
        add     sp, sp, #8
        @ sp needed for prologue
        pop     {r4, pc}

As mentioned in the comments, the cse is redundant. We can recompute the value
of (sp + 4) each time we want it. With this method we can save one instruction.


-- 
           Summary: unnecessary CSE
           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=40615


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

* [Bug target/40615] unnecessary CSE
  2009-07-02  7:39 [Bug target/40615] New: unnecessary CSE carrot at google dot com
@ 2009-07-02  7:39 ` carrot at google dot com
  2009-07-02  8:53 ` ramana at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: carrot at google dot com @ 2009-07-02  7:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from carrot at google dot com  2009-07-02 07:39 -------
Created an attachment (id=18120)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18120&action=view)
test case


-- 


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


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

* [Bug target/40615] unnecessary CSE
  2009-07-02  7:39 [Bug target/40615] New: unnecessary CSE carrot at google dot com
  2009-07-02  7:39 ` [Bug target/40615] " carrot at google dot com
@ 2009-07-02  8:53 ` ramana at gcc dot gnu dot org
  2009-07-02  9:16 ` steven at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ramana at gcc dot gnu dot org @ 2009-07-02  8:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from ramana at gcc dot gnu dot org  2009-07-02 08:53 -------
This looks like one of those rematerialization problems albeit with the stack
pointer this time. 


-- 

ramana at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-07-02 08:53:25
               date|                            |


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


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

* [Bug target/40615] unnecessary CSE
  2009-07-02  7:39 [Bug target/40615] New: unnecessary CSE carrot at google dot com
  2009-07-02  7:39 ` [Bug target/40615] " carrot at google dot com
  2009-07-02  8:53 ` ramana at gcc dot gnu dot org
@ 2009-07-02  9:16 ` steven at gcc dot gnu dot org
  2009-07-02  9:39 ` ramana at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: steven at gcc dot gnu dot org @ 2009-07-02  9:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from steven at gcc dot gnu dot org  2009-07-02 09:15 -------
Is there a C test case?  Can you add objdump of the gcc-generated asm and the
fixed asm to show the impact on code size? (/me is surprised that 3*"add
r0,sp,4" is smaller than 1**"add r0,sp,4"+3*"mov r0,r4"... Thumb is amazing :-)


-- 


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


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

* [Bug target/40615] unnecessary CSE
  2009-07-02  7:39 [Bug target/40615] New: unnecessary CSE carrot at google dot com
                   ` (2 preceding siblings ...)
  2009-07-02  9:16 ` steven at gcc dot gnu dot org
@ 2009-07-02  9:39 ` ramana at gcc dot gnu dot org
  2009-09-29  5:50 ` [Bug middle-end/40615] " pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ramana at gcc dot gnu dot org @ 2009-07-02  9:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from ramana at gcc dot gnu dot org  2009-07-02 09:39 -------
(In reply to comment #3)
> Is there a C test case?  Can you add objdump of the gcc-generated asm and the
> fixed asm to show the impact on code size? (/me is surprised that 3*"add
> r0,sp,4" is smaller than 1**"add r0,sp,4"+3*"mov r0,r4"... Thumb is amazing :-)

The length of add r0,sp,4 and mov r0,r4 is the same for Thumb1 (16 bits).


I suppose the ideal code generated would be something like this modulo errors
with stack alignments in the prologue and the epilogue. 

We also don't need r4 in that case :) . So we can save a load, a store as well
as 1 instruction over all. Smaller and faster by 1 instruction and reduced
register usage.



        push    {lr}
        sub     sp, sp, #12   (8 byte stack alignment )
        add     r0, sp, 4        // add  r0, sp, 4
        bl      _ZN1XC1Ev
        add     r0, sp, #4        // add  r0, sp, 4
        bl      _Z3barP1X
        add     r0, sp, #4       // add  r0, sp, 4
        bl      _ZN1XD1Ev
        add     sp, sp, #12    (8 byte stack alignment )
        @ sp needed for prologue
        pop     {pc}


-- 


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


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

* [Bug middle-end/40615] unnecessary CSE
  2009-07-02  7:39 [Bug target/40615] New: unnecessary CSE carrot at google dot com
                   ` (3 preceding siblings ...)
  2009-07-02  9:39 ` ramana at gcc dot gnu dot org
@ 2009-09-29  5:50 ` pinskia at gcc dot gnu dot org
  2009-09-29  5:51 ` [Bug rtl-optimization/40615] " pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-09-29  5:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2009-09-29 05:50 -------
PowerPC has the same issue.  Instructions on PPC are all the same size so 3
adds are better than one add plus 3 register moves. 
Here is a C example:
int f(int *a);
int g(int *a);
int h(int *a);

void hh(void)
{
  int t;
  f(&t);
  g(&t);
  h(&t);
}

--- CUT ---

Most RISC will have the same issue as most will have instructions which are
fixed length.

I bet this has to do with hard registers.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|target                      |middle-end
  GCC build triplet|i686-linux                  |
 GCC target triplet|arm-eabi                    |arm-eabi, powerpc*-*-*
           Keywords|                            |missed-optimization


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


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

* [Bug rtl-optimization/40615] unnecessary CSE
  2009-07-02  7:39 [Bug target/40615] New: unnecessary CSE carrot at google dot com
                   ` (4 preceding siblings ...)
  2009-09-29  5:50 ` [Bug middle-end/40615] " pinskia at gcc dot gnu dot org
@ 2009-09-29  5:51 ` pinskia at gcc dot gnu dot org
  2010-03-20 19:30 ` ramana at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-09-29  5:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pinskia at gcc dot gnu dot org  2009-09-29 05:51 -------
Before CSE:
(insn 13 2 5 2 t.c:8 (set (reg:SI 119)
        (plus:SI (reg/f:SI 113 sfp)
            (const_int 8 [0x8]))) -1 (nil))

(insn 5 13 6 2 t.c:8 (set (reg:SI 3 3)
        (reg:SI 119)) 332 {*movsi_internal1} (nil))
...
(insn 14 6 7 2 t.c:9 (set (reg:SI 120)
        (plus:SI (reg/f:SI 113 sfp)
            (const_int 8 [0x8]))) -1 (nil))

(insn 7 14 8 2 t.c:9 (set (reg:SI 3 3)
        (reg:SI 120)) 332 {*movsi_internal1} (nil))

And then after CSE, we remove the adds but we should have moved the adds into
the move.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|middle-end                  |rtl-optimization


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


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

* [Bug rtl-optimization/40615] unnecessary CSE
  2009-07-02  7:39 [Bug target/40615] New: unnecessary CSE carrot at google dot com
                   ` (5 preceding siblings ...)
  2009-09-29  5:51 ` [Bug rtl-optimization/40615] " pinskia at gcc dot gnu dot org
@ 2010-03-20 19:30 ` ramana at gcc dot gnu dot org
  2010-06-04 12:44 ` bernds at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ramana at gcc dot gnu dot org @ 2010-03-20 19:30 UTC (permalink / raw)
  To: gcc-bugs



-- 

ramana at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


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


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

* [Bug rtl-optimization/40615] unnecessary CSE
  2009-07-02  7:39 [Bug target/40615] New: unnecessary CSE carrot at google dot com
                   ` (6 preceding siblings ...)
  2010-03-20 19:30 ` ramana at gcc dot gnu dot org
@ 2010-06-04 12:44 ` bernds at gcc dot gnu dot org
  2010-06-07 22:50 ` bernds at gcc dot gnu dot org
  2010-06-08 15:31 ` hjl dot tools at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: bernds at gcc dot gnu dot org @ 2010-06-04 12:44 UTC (permalink / raw)
  To: gcc-bugs



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

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=40615


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

* [Bug rtl-optimization/40615] unnecessary CSE
  2009-07-02  7:39 [Bug target/40615] New: unnecessary CSE carrot at google dot com
                   ` (7 preceding siblings ...)
  2010-06-04 12:44 ` bernds at gcc dot gnu dot org
@ 2010-06-07 22:50 ` bernds at gcc dot gnu dot org
  2010-06-08 15:31 ` hjl dot tools at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: bernds at gcc dot gnu dot org @ 2010-06-07 22:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from bernds at gcc dot gnu dot org  2010-06-07 22:49 -------
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=40615


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

* [Bug rtl-optimization/40615] unnecessary CSE
  2009-07-02  7:39 [Bug target/40615] New: unnecessary CSE carrot at google dot com
                   ` (8 preceding siblings ...)
  2010-06-07 22:50 ` bernds at gcc dot gnu dot org
@ 2010-06-08 15:31 ` hjl dot tools at gmail dot com
  9 siblings, 0 replies; 11+ 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=40615


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

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

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-02  7:39 [Bug target/40615] New: unnecessary CSE carrot at google dot com
2009-07-02  7:39 ` [Bug target/40615] " carrot at google dot com
2009-07-02  8:53 ` ramana at gcc dot gnu dot org
2009-07-02  9:16 ` steven at gcc dot gnu dot org
2009-07-02  9:39 ` ramana at gcc dot gnu dot org
2009-09-29  5:50 ` [Bug middle-end/40615] " pinskia at gcc dot gnu dot org
2009-09-29  5:51 ` [Bug rtl-optimization/40615] " pinskia at gcc dot gnu dot org
2010-03-20 19:30 ` ramana at gcc dot gnu dot org
2010-06-04 12:44 ` bernds at gcc dot gnu dot org
2010-06-07 22:50 ` 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).