LoopRotate: don't rotate loops where the header block branches to a dead-end block.

Incomplete liveranges in the dead-end exit block can cause a missing adjacent phi-argument for a re-borrow if there is a borrow-scope is in the loop.
But even when we have complete lifetimes, it's probably not worth rotating a loop where the header block branches to a dead-end block.

Fixes a SIL verifier crash
This commit is contained in:
Erik Eckstein
2025-01-21 19:07:36 +01:00
parent 11fbd94668
commit 5dc80f62dc
2 changed files with 47 additions and 0 deletions

View File

@@ -18,6 +18,7 @@
#include "swift/SIL/SILBuilder.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/SILOptimizer/Analysis/Analysis.h"
#include "swift/SILOptimizer/Analysis/DeadEndBlocksAnalysis.h"
#include "swift/SILOptimizer/Analysis/DominanceAnalysis.h"
#include "swift/SILOptimizer/Analysis/LoopAnalysis.h"
#include "swift/SILOptimizer/PassManager/Passes.h"
@@ -374,6 +375,15 @@ static bool rotateLoop(SILLoop *loop, DominanceInfo *domInfo,
return false;
}
// Incomplete liveranges in the dead-end exit block can cause a missing adjacent
// phi-argument for a re-borrow if there is a borrow-scope is in the loop.
// But even when we have complete lifetimes, it's probably not worth rotating
// a loop where the header block branches to a dead-end block.
auto *deBlocks = pm->getAnalysis<DeadEndBlocksAnalysis>()->get(exit->getParent());
if (deBlocks->isDeadEnd(exit)) {
return false;
}
// We don't want to rotate such that we merge two headers of separate loops
// into one. This can be turned into an assert again once we have guaranteed
// preheader insertions.