Skip to content

Commit 3b60184

Browse files
committed
"[NFC] Add tests for LoopUnroll on OSSA""
Reland #35423
1 parent 8d217f3 commit 3b60184

File tree

2 files changed

+731
-4
lines changed

2 files changed

+731
-4
lines changed

lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,11 @@ updateSSA(SILModule &M, SILLoop *Loop,
347347
}
348348

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

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

365366
Optional<uint64_t> MaxTripCount =
366367
getMaxLoopTripCount(Loop, Preheader, Header, Latch);
367-
if (!MaxTripCount)
368+
if (!MaxTripCount) {
369+
LLVM_DEBUG(llvm::dbgs() << "Not unrolling, did not find trip count\n");
368370
return false;
371+
}
369372

370-
if (!canAndShouldUnrollLoop(Loop, MaxTripCount.getValue()))
373+
if (!canAndShouldUnrollLoop(Loop, MaxTripCount.getValue())) {
374+
LLVM_DEBUG(llvm::dbgs() << "Not unrolling, exceeds cost threshold\n");
371375
return false;
376+
}
372377

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

444449
void run() override {
445450
bool Changed = false;
446-
447451
auto *Fun = getFunction();
448452
SILLoopInfo *LoopInfo = PM->getAnalysis<SILLoopAnalysis>()->get(Fun);
449453

@@ -462,6 +466,12 @@ class LoopUnrolling : public SILFunctionTransform {
462466
}
463467
}
464468

469+
if (InnermostLoops.empty())
470+
return;
471+
472+
LLVM_DEBUG(llvm::dbgs() << "Loop Unroll running on function : "
473+
<< Fun->getName() << "\n");
474+
465475
// Try to unroll innermost loops.
466476
for (auto *Loop : InnermostLoops)
467477
Changed |= tryToUnrollLoop(Loop);

0 commit comments

Comments
 (0)