llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[InstCombine] scalbn should be canonicalized to ldexp

Open Andarwinux opened this issue 3 months ago • 1 comments

https://godbolt.org/z/z4Maf734d

double foo(double a, int b){
    return __builtin_scalbn(a,b);
}

double bar(double a, int b){
    return __builtin_ldexp(a,b);
}
foo(double, int):
        jmp     scalbn@PLT

bar(double, int):
        vcvtsi2sd       xmm1, xmm15, edi
        vscalefsd       xmm0, xmm0, xmm1
        ret
foo(double, int):
        b       scalbn

bar(double, int):
        sxtw    x8, w0
        ptrue   p0.d
        fmov    d1, x8
        fscale  z0.d, p0/m, z0.d, z1.d
        ret

For many backends, scalbn and ldexp are equivalent, but ldexp can be inlined while scalbn cannot. best to uniformly canonicalize them to ldexp in InstCombine.

Andarwinux avatar Aug 15 '26 08:08 Andarwinux

Hi, I'd be interested in working on this. Could you assign it to me?

ChrisLee02 avatar Aug 15 '26 11:08 ChrisLee02