[llvm] [AArch64] Unrolling of loops with vector instructions. (PR #147420)

Ahmad Yasin via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 20 08:11:46 PDT 2025


ayasin-a wrote:

> It looks like this patch now also prevents the unroll of the original scalar loop when the alias/iter checks fail. Seems like all the variants of the loop share the `"llvm.loop.isvectorized"` metadata so none of the variants will be unrolled.
> 
> See example: https://godbolt.org/z/nn1fh67ns

Thanks for reporting this @UsmanNadeem . I examined your example on macOS. Here is what happens:
1. On baseline compiler, before my change, the scalar version of your loop is also not unrolled due to its constant tripcount.
2. This is maintained after my change.
3. When I move to a variable tripcount in your test loop. The baseline compiler would not unroll it too since due to the same autovectorized metadata check inside `getAppleRuntimeUnrollPreferences()`.
4. Now the same behavior in 3 is maintained in the new compiler. Yes its true that we hoisted that same check to the ARM generic code, but it would skip unrolling at a later stage on my system.

If you are interested in a particular mtriple/mcpu I may be able to have a look.

Also it would be nice to expand on why the scalar version of the loop needs to be highly optimized once the primary loop is autovectorized. 

https://github.com/llvm/llvm-project/pull/147420


More information about the llvm-commits mailing list