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

[aarch64] Missed MADD folding opportunity

Open pzhengqc opened this issue 2 months ago • 1 comments

For the following function foo,

long foo(long stride, int mvx, int mvy)
{
    return (long)(mvy >> 2) * stride + (mvx >> 2);
}

LLVM currently generates MUL+ADD, instead of MADD.

foo:
        sbfx    x8, x2, #2, #30
        asr     w9, w1, #2
        mul     x8, x0, x8
        add     x0, x8, w9, sxtw
        ret

With MADD, we could generate the following:

foo:
        sbfx    x8, x2, #2, #30
        sbfx    x9, x1, #2, #30
        madd    x0, x0, x8, x9

The test case was found in DCPerf's VideoTranscodeBench benchmark.

pzhengqc avatar Sep 18 '26 17:09 pzhengqc

@llvm/issue-subscribers-backend-aarch64

Author: pzhengqc

For the following function foo, ``` long foo(long stride, int mvx, int mvy) { return (long)(mvy >> 2) * stride + (mvx >> 2); } ``` LLVM currently generates MUL+ADD, instead of MADD. ``` foo: sbfx x8, x2, #2, #30 asr w9, w1, #2 mul x8, x0, x8 add x0, x8, w9, sxtw ret ``` With MADD, we could generate the following: ``` foo: sbfx x8, x2, #2, #30 sbfx x9, x1, #2, #30 madd x0, x0, x8, x9 ``` The test case was found in DCPerf's VideoTranscodeBench benchmark.