Skip to content

[C++23] I want [[assume(p1 != p2)]] can be optimized as __restrict #120879

@SekaiArendelle

Description

@SekaiArendelle

source code:

int f(int *a, int *__restrict b) noexcept {
    *a = 1;
    *b = 2;
    return *a + *b;
}

int f2(int *a, int *b) noexcept {
    [[assume(a != b)]];
    *a = 1;
    *b = 2;
    return *a + *b;
}

output:

f(int*, int*):
        mov     dword ptr [rdi], 1
        mov     dword ptr [rsi], 2
        mov     eax, 3
        ret

f2(int*, int*):
        mov     dword ptr [rdi], 1
        mov     dword ptr [rsi], 2
        mov     eax, dword ptr [rdi]
        add     eax, 2
        ret

compile with -std=c++23 -O3

Metadata

Metadata

Assignees

No one assigned

    Labels

    llvm:optimizationsquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions