llvm / llvm/llvm-project

[AArch64] No runtime unrolling happens even when it's performant

Open
#222,532 4 comments 0 reactions 1 assignee Claimed by @ShikharJ-Corp View on GitHub
backend:AArch64 missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

### Compile command:

`-Ofast -Rpass=loop-unroll -mcpu=cortex-a57`

### For kernels like,

```c
int stride = 3;
n = n/stride;
int A = 2;
int B = 3;
for (i = 0; i < n; i+=10)
{
dst[0] += A*src[0] + B*src[1];
dst[1] += A*src[1] + B*src[2];
dst[2] += A*src[2] + B*src[3];
dst[3] += A*src[3] + B*src[4];
dst[4] += A*src[4] + B*src[5];
dst[5] += A*src[5] + B*src[6];
dst[6] += A*src[6] + B*src[7];
dst[7] += A*src[7] + B*src[8];
dst += stride;
src += stride;
}
```

### Summary

When comparing this kernel's asm generated by latest llvm with gcc-16.0 then it is observed that gcc is able to do loop-unroll , where as clang proceeds with slp vectorization but fails to do unroll. Then for the selected cpu-model , clang performs relatively dips by ~20-30% .
**_On forcing a runtime-unroll count of 2 incase of clang , we see a relatively improved perf by ~30%_**
**_Hence loop-unrolling is the key transform.._**

Workspace links->
-> GCC: https://godbolt.org/z/GhsYx18E8
-> Clang: https://godbolt.org/z/x9os8r6EG

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.