[llvm] 469f0fc - [SimpleLoopUnswitch] Clear dispos in deleteDeadBlocksFromLoop.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 5 02:28:43 PDT 2022
Author: Florian Hahn
Date: 2022-10-05T10:28:15+01:00
New Revision: 469f0fc6a652cf2c8b6e68c21af895757b3cad5d
URL: https://github.com/llvm/llvm-project/commit/469f0fc6a652cf2c8b6e68c21af895757b3cad5d
DIFF: https://github.com/llvm/llvm-project/commit/469f0fc6a652cf2c8b6e68c21af895757b3cad5d.diff
LOG: [SimpleLoopUnswitch] Clear dispos in deleteDeadBlocksFromLoop.
SimpleLoopUnswitch may remove blocks from loops. Clear block and loop
dispositions in that case, to clean up invalid entries in the cache.
Fixes #58158.
Fixes #58159.
Added:
Modified:
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
llvm/test/Transforms/SimpleLoopUnswitch/invalidate-block-and-loop-dispositions.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
index c1e67afb29e13..b07408451862f 100644
--- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -1620,6 +1620,7 @@ deleteDeadBlocksFromLoop(Loop &L,
SmallVectorImpl<BasicBlock *> &ExitBlocks,
DominatorTree &DT, LoopInfo &LI,
MemorySSAUpdater *MSSAU,
+ ScalarEvolution *SE,
function_ref<void(Loop &, StringRef)> DestroyLoopCB) {
// Find all the dead blocks tied to this loop, and remove them from their
// successors.
@@ -1671,6 +1672,8 @@ deleteDeadBlocksFromLoop(Loop &L,
"If the child loop header is dead all blocks in the child loop must "
"be dead as well!");
DestroyLoopCB(*ChildL, ChildL->getName());
+ if (SE)
+ SE->forgetBlockAndLoopDispositions();
LI.destroy(ChildL);
return true;
});
@@ -2377,7 +2380,7 @@ static void unswitchNontrivialInvariants(
// Now that our cloned loops have been built, we can update the original loop.
// First we delete the dead blocks from it and then we rebuild the loop
// structure taking these deletions into account.
- deleteDeadBlocksFromLoop(L, ExitBlocks, DT, LI, MSSAU, DestroyLoopCB);
+ deleteDeadBlocksFromLoop(L, ExitBlocks, DT, LI, MSSAU, SE,DestroyLoopCB);
if (MSSAU && VerifyMemorySSA)
MSSAU->getMemorySSA()->verifyMemorySSA();
diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/invalidate-block-and-loop-dispositions.ll b/llvm/test/Transforms/SimpleLoopUnswitch/invalidate-block-and-loop-dispositions.ll
index 29449c8265e4c..c7ce403f808eb 100644
--- a/llvm/test/Transforms/SimpleLoopUnswitch/invalidate-block-and-loop-dispositions.ll
+++ b/llvm/test/Transforms/SimpleLoopUnswitch/invalidate-block-and-loop-dispositions.ll
@@ -71,3 +71,42 @@ exit: ; preds = %then.bb, %loop.head
}
declare i16 @foo() nounwind readnone
+
+define void @test_pr58158(i1 %c.1) {
+; CHECK-LABEL: @test_pr58158(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CALL:%.*]] = tail call i16 @bar()
+; CHECK-NEXT: br i1 [[C_1:%.*]], label [[ENTRY_SPLIT_US:%.*]], label [[ENTRY_SPLIT:%.*]]
+; CHECK: entry.split.us:
+; CHECK-NEXT: br label [[OUTER_US:%.*]]
+; CHECK: outer.us:
+; CHECK-NEXT: br label [[INNER_PREHEADER_US:%.*]]
+; CHECK: inner.us:
+; CHECK-NEXT: [[C_2_US:%.*]] = icmp eq i16 0, [[CALL]]
+; CHECK-NEXT: br i1 [[C_2_US]], label [[OUTER_LOOPEXIT_US:%.*]], label [[INNER_US:%.*]]
+; CHECK: inner.preheader.us:
+; CHECK-NEXT: br label [[INNER_US]]
+; CHECK: outer.loopexit.us:
+; CHECK-NEXT: br label [[OUTER_BACKEDGE_US:%.*]]
+; CHECK: outer.backedge.us:
+; CHECK-NEXT: br label [[OUTER_US]]
+; CHECK: entry.split:
+; CHECK-NEXT: br label [[OUTER:%.*]]
+; CHECK: outer:
+; CHECK-NEXT: br label [[OUTER_BACKEDGE:%.*]]
+; CHECK: outer.backedge:
+; CHECK-NEXT: br label [[OUTER]]
+;
+entry:
+ %call = tail call i16 @bar()
+ br label %outer
+
+outer:
+ br i1 %c.1, label %inner, label %outer
+
+inner:
+ %c.2 = icmp eq i16 0, %call
+ br i1 %c.2, label %outer, label %inner
+}
+
+declare i16 @bar()
More information about the llvm-commits
mailing list