[llvm] [RISCV] Adjust unroll prefs for loops with vectors (PR #151525)
Ahmad Yasin via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 3 12:37:25 PDT 2025
================
@@ -2627,18 +2627,17 @@ void RISCVTTIImpl::getUnrollingPreferences(
if (L->getNumBlocks() > 4)
return;
- // Don't unroll vectorized loops, including the remainder loop
- if (getBooleanLoopAttribute(L, "llvm.loop.isvectorized"))
- return;
-
// Scan the loop: don't unroll loops with calls as this could prevent
- // inlining.
+ // inlining. Don't unroll auto-vectorized loops either, though do allow
+ // unrolling of the scalar remainder.
+ bool IsVectorized = getBooleanLoopAttribute(L, "llvm.loop.isvectorized");
InstructionCost Cost = 0;
for (auto *BB : L->getBlocks()) {
for (auto &I : *BB) {
- // Initial setting - Don't unroll loops containing vectorized
- // instructions.
- if (I.getType()->isVectorTy())
+ // Both auto-vectorized loops and the scalar remainder have the
+ // isvectorized attribute, so differentiate between them by the presence
+ // of vector instructions.
+ if (IsVectorized && I.getType()->isVectorTy())
return;
----------------
ayasin-a wrote:
Thanks for introducing this enhancement!
It would help if the code would could add an attribute or a field to the Loop instance that this is actually the "remainder of a loop that has `isvectorized` attribute. This way any later-on check, for example in a target-specific tuning, would leverage the same without re-iterating over each and every instruction in the loop.
@fhahn
https://github.com/llvm/llvm-project/pull/151525
More information about the llvm-commits
mailing list