Skip to content

Commit 1bf8ae1

Browse files
committed
[SimpleLoopUnswitch] Forget loops before invalidating IR.
Invalidate SCEV before adjusting switch instruction, so the IR remains in a valid state for SCEV invalidation.
1 parent 3b74224 commit 1bf8ae1

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -791,15 +791,25 @@ static bool unswitchTrivialSwitch(Loop &L, SwitchInst &SI, DominatorTree &DT,
791791
Loop *OuterL = &L;
792792

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

800+
if (SE) {
801+
if (OuterL)
802+
SE->forgetLoop(OuterL);
803+
else
804+
SE->forgetTopmostLoop(&L);
805+
}
806+
807+
if (DefaultExitBB) {
808+
// Clear out the default destination temporarily to allow accurate
809+
// predecessor lists to be examined below.
810+
SI.setDefaultDest(nullptr);
811+
}
812+
803813
// Store the exit cases into a separate data structure and remove them from
804814
// the switch.
805815
SmallVector<std::tuple<ConstantInt *, BasicBlock *,
@@ -822,13 +832,6 @@ static bool unswitchTrivialSwitch(Loop &L, SwitchInst &SI, DominatorTree &DT,
822832
SIW.removeCase(CaseI);
823833
}
824834

825-
if (SE) {
826-
if (OuterL)
827-
SE->forgetLoop(OuterL);
828-
else
829-
SE->forgetTopmostLoop(&L);
830-
}
831-
832835
// Check if after this all of the remaining cases point at the same
833836
// successor.
834837
BasicBlock *CommonSuccBB = nullptr;

0 commit comments

Comments
 (0)