Skip to content

Does not CSE b&c in a&b&c #118036

@Alcaro

Description

@Alcaro
// Type your code here, or load an example.
void square(unsigned board, unsigned& e, unsigned& f) {
    unsigned a = (board >> 1) & board;
    unsigned b = (board >> 5) & board;
    unsigned c = (board << 5) & board;
    e = (b&c);
    f = (a&b&c);
}
void cube(unsigned board, unsigned& e, unsigned& f) {
    unsigned a = (board >> 1) & board;
    unsigned b = (board >> 5) & board;
    unsigned c = (board << 5) & board;
    e = (b&c);
    f = (a&(b&c));
}

https://godbolt.org/z/YvKoW8jza

Expected: Since the only difference is an extra paren on the f line, the b&c should be deemed a common subexpression and deduplicated

Actual:

square(unsigned int, unsigned int&, unsigned int&):
        mov     eax, edi
        shr     eax
        mov     ecx, edi
        shl     ecx, 5
        mov     r8d, ecx
        and     r8d, edi
        and     eax, edi
        shr     edi, 5
        and     r8d, edi
        mov     dword ptr [rsi], r8d
        and     ecx, edi
        and     ecx, eax
        mov     dword ptr [rdx], ecx
        ret

cube(unsigned int, unsigned int&, unsigned int&):
        mov     eax, edi
        shr     eax, 5
        mov     ecx, edi
        shl     ecx, 5
        and     ecx, eax
        and     ecx, edi
        shr     edi
        mov     dword ptr [rsi], ecx
        and     ecx, edi
        mov     dword ptr [rdx], ecx
        ret

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions