https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61984

            Bug ID: 61984
           Summary: use mr. to remove extra cmp instruction on ppc
           Product: gcc
           Version: 4.10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: carrot at google dot com
            Target: powerpc64le

Compile following code with options  -m64 -mcpu=power8 -O2


extern void free (void *__ptr);

void my_free ( void* p, void* addr )
{
   if (addr != ((void *)0)) free ( addr );
}


Trunk gcc generates:

my_free:
0:    addis 2,12,.TOC.-0b@ha
    addi 2,2,.TOC.-0b@l
    .localentry    my_free,.-my_free
    cmpdi 0,4,0     //    mr.  3,4
    beqlr 0         //    beqlr 0
    mflr 0          //    mflr  0
    mr 3,4          //
    std 0,16(1)
    stdu 1,-32(1)
    bl free
    nop
    addi 1,1,32
    ld 0,16(1)
    mtlr 0
    blr


The instructions from cmpdi to mr can be changed to following

        mr.   3, 4
        beqlr 0
        mflr  0
        ...

so we can remove the cmpdi instruction.

Reply via email to