This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/53869] Redundant memory load


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

--- Comment #1 from brag <unixoid2003 at mail dot ru> 2012-07-06 06:16:05 UTC ---
class test{
public:
    void remove();
private:
    test *next;
    test *prev;
};

void test::remove(){
    next->prev=prev;
    prev->next=next;
}

arm-none-eabi-gcc++ -mcpu=cortex-m3 -mthumb -O2

00000000 <_ZN4test6removeEv>:
   0:    6803          ldr    r3, [r0, #0]
   2:    6842          ldr    r2, [r0, #4]
   4:    605a          str    r2, [r3, #4]
   6:    6842          ldr    r2, [r0, #4]   ; Redundant
   8:    6013          str    r3, [r2, #0]
   a:    4770          bx    lr

But this code compiles better:

void test::remove(){
    test *n=next,*p=prev;
    n->prev=p;
    p->next=n;
}

00000000 <_ZN4test6removeEv>:
   0:    e890 000c     ldmia.w    r0, {r2, r3}
   4:    6053          str    r3, [r2, #4]
   6:    601a          str    r2, [r3, #0]
   8:    4770          bx    lr


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]