Skip to content

"[NFC] Add tests for LoopUnroll on OSSA"" #35534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,11 @@ updateSSA(SILModule &M, SILLoop *Loop,
}

/// Try to fully unroll the loop if we can determine the trip count and the trip
/// count lis below a threshold.
/// count is below a threshold.
static bool tryToUnrollLoop(SILLoop *Loop) {
assert(Loop->getSubLoops().empty() && "Expecting innermost loops");

LLVM_DEBUG(llvm::dbgs() << "Trying to unroll loop : \n" << *Loop);
auto *Preheader = Loop->getLoopPreheader();
if (!Preheader)
return false;
Expand All @@ -364,11 +365,15 @@ static bool tryToUnrollLoop(SILLoop *Loop) {

Optional<uint64_t> MaxTripCount =
getMaxLoopTripCount(Loop, Preheader, Header, Latch);
if (!MaxTripCount)
if (!MaxTripCount) {
LLVM_DEBUG(llvm::dbgs() << "Not unrolling, did not find trip count\n");
return false;
}

if (!canAndShouldUnrollLoop(Loop, MaxTripCount.getValue()))
if (!canAndShouldUnrollLoop(Loop, MaxTripCount.getValue())) {
LLVM_DEBUG(llvm::dbgs() << "Not unrolling, exceeds cost threshold\n");
return false;
}

// TODO: We need to split edges from non-condbr exits for the SSA updater. For
// now just don't handle loops containing such exits.
Expand Down Expand Up @@ -443,7 +448,6 @@ class LoopUnrolling : public SILFunctionTransform {

void run() override {
bool Changed = false;

auto *Fun = getFunction();
SILLoopInfo *LoopInfo = PM->getAnalysis<SILLoopAnalysis>()->get(Fun);

Expand All @@ -462,6 +466,12 @@ class LoopUnrolling : public SILFunctionTransform {
}
}

if (InnermostLoops.empty())
return;

LLVM_DEBUG(llvm::dbgs() << "Loop Unroll running on function : "
<< Fun->getName() << "\n");

// Try to unroll innermost loops.
for (auto *Loop : InnermostLoops)
Changed |= tryToUnrollLoop(Loop);
Expand Down
Loading