Skip to content

Commit

Permalink
[SimpleLoopUnswitch] Forget loops before invalidating IR.
Browse files Browse the repository at this point in the history
Invalidate SCEV before adjusting switch instruction, so the IR remains
in a valid state for SCEV invalidation.
  • Loading branch information
fhahn committed Mar 1, 2023
1 parent 3b74224 commit 1bf8ae1
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
Expand Up @@ -791,15 +791,25 @@ static bool unswitchTrivialSwitch(Loop &L, SwitchInst &SI, DominatorTree &DT,
Loop *OuterL = &L;

if (DefaultExitBB) {
// Clear out the default destination temporarily to allow accurate
// predecessor lists to be examined below.
SI.setDefaultDest(nullptr);
// Check the loop containing this exit.
Loop *ExitL = LI.getLoopFor(DefaultExitBB);
if (!ExitL || ExitL->contains(OuterL))
OuterL = ExitL;
}

if (SE) {
if (OuterL)
SE->forgetLoop(OuterL);
else
SE->forgetTopmostLoop(&L);
}

if (DefaultExitBB) {
// Clear out the default destination temporarily to allow accurate
// predecessor lists to be examined below.
SI.setDefaultDest(nullptr);
}

// Store the exit cases into a separate data structure and remove them from
// the switch.
SmallVector<std::tuple<ConstantInt *, BasicBlock *,
Expand All @@ -822,13 +832,6 @@ static bool unswitchTrivialSwitch(Loop &L, SwitchInst &SI, DominatorTree &DT,
SIW.removeCase(CaseI);
}

if (SE) {
if (OuterL)
SE->forgetLoop(OuterL);
else
SE->forgetTopmostLoop(&L);
}

// Check if after this all of the remaining cases point at the same
// successor.
BasicBlock *CommonSuccBB = nullptr;
Expand Down

0 comments on commit 1bf8ae1

Please sign in to comment.