Skip to content

Missed DCE for __builtin_{clzg,ctzg} when bitshift #139944

Open
@BreadTom

Description

@BreadTom

Godbolt and GCC bug

unsigned long f0(unsigned long arg0, int arg1){
    int tmp1;
    if(arg1){
        tmp1 = __builtin_ctzg(arg0, 0);
        return (arg0 >> tmp1);
    }
    tmp1 = __builtin_clzg(arg0, 0);
    return (arg0 << tmp1);
}

unsigned long f1(unsigned long arg0, int arg1){
    int tmp1;
    if(arg1){
        tmp1 = __builtin_clzg(arg0, 0);
        arg0 <<= tmp1;
        tmp1 = __builtin_ctzg(arg0, 0);
        arg0 >>= tmp1;
        return arg0;
    }
    tmp1 = __builtin_ctzg(arg0, 0);
    arg0 >>= tmp1;
    tmp1 = __builtin_clzg(arg0, 0);
    arg0 <<= tmp1;
    return arg0;
}

f1() uses __builtin_ctzg() then __builtin_clzg() for returning ARG0 when it could instead use __builtin_clzg() in f0() (Vice versa) with flags -O3 -march=icelake-client.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions