Bug 41742 - Unnecessary zero-extension at -O2 but not -O1
Summary: Unnecessary zero-extension at -O2 but not -O1
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-18 13:56 UTC by Segher Boessenkool
Modified: 2012-08-16 10:39 UTC (History)
2 users (show)

See Also:
Host:
Target: powerpc-linux
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-08-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Segher Boessenkool 2009-10-18 13:56:15 UTC
Take the following example:

void *memset(void *b, int c, unsigned long len)
{
        unsigned long i;

        for (i = 0; i < len; i++)
                ((unsigned char *)b)[i] = c;

        return b;
}

-O2 generates:

memset:
        cmpwi 0,5,0
        beqlr 0
        mtctr 5
        rlwinm 4,4,0,0xff
        li 9,0
        .p2align 4,,15
.L3:
        stbx 4,3,9
        addi 9,9,1
        bdnz .L3
        blr

The zero-extension of GPR4 isn't needed, and in fact, -O1 doesn't
generate it:

memset:
        cmpwi 0,5,0
        beqlr 0
        li 9,0
        subf 5,9,5
        mtctr 5
.L3:
        stbx 4,3,9
        addi 9,9,1
        bdnz .L3
        blr

(the subf here is superfluous though).
Comment 1 Segher Boessenkool 2012-08-16 10:39:45 UTC
Still happens on mainline: -O2 still has the superfluous sign-extend,
but now the -O1 code is perfect.