Skip to content

LLVM is too quick to run LowerExpectIntrinsicPass requiring redundant expect calls #199610

@ruriww

Description

@ruriww

https://godbolt.org/z/dE7eGzojn

bool is_multiple_of(unsigned a, unsigned b) {
    return __builtin_expect(a % b == 0, 1);
}

unsigned test(unsigned n, unsigned* out) {
    auto b = is_multiple_of(n, 2);

    if (b) {
        return 0;
    } else {
        *out = 0;

        return 1;
    }
}

unsigned test2(unsigned n, unsigned* out) {
    auto b = is_multiple_of(n, 2);

    // redundant expect call
    if (__builtin_expect(b, 1)) {
        return 0;
    } else {
        *out = 0;

        return 1;
    }
}
test(unsigned int, unsigned int*):
        xor     eax, eax
        test    dil, 1
        je      .LBB1_2
        mov     dword ptr [rsi], 0
        mov     eax, 1
.LBB1_2:
        ret

test2(unsigned int, unsigned int*):
        xor     eax, eax
        test    dil, 1
        jne     .LBB2_1
        ret
.LBB2_1:
        mov     dword ptr [rsi], 0
        mov     eax, 1
        ret

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions