llvm/llvm-project

~llvm.fsh[rl] patterns not recognized

Open

#173.132 aperta il 20 dic 2025

Vedi su GitHub
 (6 commenti) (1 reazione) (1 assegnatario)C++ (10.782 fork)batch import
good first issuellvm:instcombinellvm:optimizationsmissed-optimization

Metriche repository

Star
 (26.378 star)
Metriche merge PR
 (Merge medio 1g 2h) (1000 PR mergiate in 30 g)

Descrizione

Zig Godbolt LLVM Godbolt

Example 1:

export fn rotate(x: u64, y: u64) u64 {
    return x >> @truncate(~y) | x << @truncate(y + 1);
}

Should be:

rotate:
        lea     ecx, [rsi + 1]
        mov     rax, rdi
        rol     rax, cl
        ret

Example 2:

export fn rotate2(x: u64, y: u64) u64 {
    return x >> @truncate(y + 1) | x << @truncate(~y);
}

Should be:

rotate2:
        lea     ecx, [rsi + 1]
        mov     rax, rdi
        ror     rax, cl
        ret

Might not be useful in most situations, but these are also valid transformations:

rotate:
        mov     rcx, rsi
        not     cl
        mov     rax, rdi
        ror     rax, cl
        ret

rotate2:
        mov     rcx, rsi
        not     cl
        mov     rax, rdi
        rol     rax, cl
        ret

Guida contributor