Skip to content

Commit fd175fa

Browse files
authored
[RISCV] Adjust unroll prefs for loops with vectors (#151525)
Adjust the unrolling preferences to unroll hand-vectorized code, as well as the scalar remainder of a vectorized loop. Inspired by a similar effort in AArch64: see #147420 and #151164.
1 parent 68b9bb5 commit fd175fa

File tree

2 files changed

+610
-8
lines changed

2 files changed

+610
-8
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,18 +2627,17 @@ void RISCVTTIImpl::getUnrollingPreferences(
26272627
if (L->getNumBlocks() > 4)
26282628
return;
26292629

2630-
// Don't unroll vectorized loops, including the remainder loop
2631-
if (getBooleanLoopAttribute(L, "llvm.loop.isvectorized"))
2632-
return;
2633-
26342630
// Scan the loop: don't unroll loops with calls as this could prevent
2635-
// inlining.
2631+
// inlining. Don't unroll auto-vectorized loops either, though do allow
2632+
// unrolling of the scalar remainder.
2633+
bool IsVectorized = getBooleanLoopAttribute(L, "llvm.loop.isvectorized");
26362634
InstructionCost Cost = 0;
26372635
for (auto *BB : L->getBlocks()) {
26382636
for (auto &I : *BB) {
2639-
// Initial setting - Don't unroll loops containing vectorized
2640-
// instructions.
2641-
if (I.getType()->isVectorTy())
2637+
// Both auto-vectorized loops and the scalar remainder have the
2638+
// isvectorized attribute, so differentiate between them by the presence
2639+
// of vector instructions.
2640+
if (IsVectorized && I.getType()->isVectorTy())
26422641
return;
26432642

26442643
if (isa<CallInst>(I) || isa<InvokeInst>(I)) {

0 commit comments

Comments
 (0)