Skip to content

Commit 9d8cd0b

Browse files
author
Marek Sedlacek
committed
Added indication of loop rotation when no unroll happens
1 parent d49e403 commit 9d8cd0b

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

llvm/include/llvm/Transforms/Utils/UnrollLoop.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ enum class LoopUnrollResult {
5959
/// The loop was not modified.
6060
Unmodified,
6161

62+
/// The loop was modified, but not unrolled.
63+
Modified,
64+
6265
/// The loop was partially unrolled -- we still have a loop, but with a
6366
/// smaller trip count. We may also have emitted epilogue loop if the loop
6467
/// had a non-constant trip count.

llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,8 +1357,9 @@ tryToUnrollLoop(Loop *L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE,
13571357
ULO.RuntimeUnrollMultiExit = UP.RuntimeUnrollMultiExit;
13581358
LoopUnrollResult UnrollResult = UnrollLoop(
13591359
L, ULO, LI, &SE, &DT, &AC, &TTI, &ORE, PreserveLCSSA, &RemainderLoop, AA);
1360-
if (UnrollResult == LoopUnrollResult::Unmodified)
1361-
return LoopUnrollResult::Unmodified;
1360+
if (UnrollResult == LoopUnrollResult::Unmodified ||
1361+
UnrollResult == LoopUnrollResult::Modified)
1362+
return UnrollResult;
13621363

13631364
if (RemainderLoop) {
13641365
std::optional<MDNode *> RemainderLoopID =

llvm/lib/Transforms/Utils/LoopUnroll.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
485485

486486
assert(ULO.Count > 0);
487487

488+
LoopUnrollResult Result = LoopUnrollResult::Unmodified;
489+
488490
if (ULO.Runtime && SE) {
489491
BasicBlock *OrigHeader = L->getHeader();
490492
BranchInst *BI = dyn_cast<BranchInst>(OrigHeader->getTerminator());
@@ -499,10 +501,12 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
499501
SQ.TLI = nullptr;
500502
SQ.DT = DT;
501503
SQ.AC = AC;
502-
llvm::LoopRotation(L, LI, TTI, AC, DT, SE, nullptr /*MemorySSAUpdater*/,
503-
SQ, false /*RotationOnly*/, 16 /*Threshold*/,
504-
false /*IsUtilMode*/, false /*PrepareForLTO*/,
505-
[](Loop *, ScalarEvolution *) { return true; });
504+
if (llvm::LoopRotation(L, LI, TTI, AC, DT, SE,
505+
nullptr /*MemorySSAUpdater*/, SQ,
506+
false /*RotationOnly*/, 16 /*Threshold*/,
507+
false /*IsUtilMode*/, false /*PrepareForLTO*/,
508+
[](Loop *, ScalarEvolution *) { return true; }))
509+
Result = LoopUnrollResult::Modified;
506510
}
507511
}
508512

@@ -599,7 +603,7 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
599603
if (!LatchBI || (LatchBI->isConditional() && !LatchIsExiting)) {
600604
LLVM_DEBUG(
601605
dbgs() << "Can't unroll; a conditional latch must exit the loop");
602-
return LoopUnrollResult::Unmodified;
606+
return Result;
603607
}
604608

605609
assert((!ULO.Runtime || canHaveUnrollRemainder(L)) &&
@@ -620,7 +624,7 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
620624
else {
621625
LLVM_DEBUG(dbgs() << "Won't unroll; remainder loop could not be "
622626
"generated when assuming runtime trip count\n");
623-
return LoopUnrollResult::Unmodified;
627+
return Result;
624628
}
625629
}
626630

0 commit comments

Comments
 (0)