Skip to content

Commit 23d18dd

Browse files
committed
[LoopFusion] Forget loop and block dispositions after latch merge
Merging the latches of loops may affect the dispositions, so they should be forgotten after the merge. This patch will fix the crash due to using loop dispositions after forgetting them.
1 parent 009706f commit 23d18dd

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

llvm/lib/Transforms/Scalar/LoopFuse.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,14 +1796,15 @@ struct LoopFuser {
17961796
// mergeLatch may remove the only block in FC1.
17971797
SE.forgetLoop(FC1.L);
17981798
SE.forgetLoop(FC0.L);
1799-
// Forget block dispositions as well, so that there are no dangling
1800-
// pointers to erased/free'ed blocks.
1801-
SE.forgetBlockAndLoopDispositions();
18021799

18031800
// Move instructions from FC0.Latch to FC1.Latch.
18041801
// Note: mergeLatch requires an updated DT.
18051802
mergeLatch(FC0, FC1);
18061803

1804+
// Forget block dispositions as well, so that there are no dangling
1805+
// pointers to erased/free'ed blocks.
1806+
SE.forgetBlockAndLoopDispositions();
1807+
18071808
// Merge the loops.
18081809
SmallVector<BasicBlock *, 8> Blocks(FC1.L->blocks());
18091810
for (BasicBlock *BB : Blocks) {
@@ -2092,14 +2093,15 @@ struct LoopFuser {
20922093
// mergeLatch may remove the only block in FC1.
20932094
SE.forgetLoop(FC1.L);
20942095
SE.forgetLoop(FC0.L);
2095-
// Forget block dispositions as well, so that there are no dangling
2096-
// pointers to erased/free'ed blocks.
2097-
SE.forgetBlockAndLoopDispositions();
20982096

20992097
// Move instructions from FC0.Latch to FC1.Latch.
21002098
// Note: mergeLatch requires an updated DT.
21012099
mergeLatch(FC0, FC1);
21022100

2101+
// Forget block dispositions as well, so that there are no dangling
2102+
// pointers to erased/free'ed blocks.
2103+
SE.forgetBlockAndLoopDispositions();
2104+
21032105
// Merge the loops.
21042106
SmallVector<BasicBlock *, 8> Blocks(FC1.L->blocks());
21052107
for (BasicBlock *BB : Blocks) {

0 commit comments

Comments
 (0)