[llvm-branch-commits] [llvm] b980bed - [MSSAUpdater] Skip renaming when inserting def in unreachable block.
Florian Hahn via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Dec 29 10:28:20 PST 2020
Author: Florian Hahn
Date: 2020-12-29T18:22:12Z
New Revision: b980bed34b96a9a85c256b1627ef9339d82829eb
URL: https://github.com/llvm/llvm-project/commit/b980bed34b96a9a85c256b1627ef9339d82829eb
DIFF: https://github.com/llvm/llvm-project/commit/b980bed34b96a9a85c256b1627ef9339d82829eb.diff
LOG: [MSSAUpdater] Skip renaming when inserting def in unreachable block.
This fixes a updater crash when moving memory defs between unreachable
blocks.
Fixes PR48616.
Added:
Modified:
llvm/lib/Analysis/MemorySSAUpdater.cpp
llvm/test/Transforms/GVN/preserve-memoryssa.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp
index f633fbe4e12b..4ff61d4324f8 100644
--- a/llvm/lib/Analysis/MemorySSAUpdater.cpp
+++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp
@@ -431,10 +431,11 @@ void MemorySSAUpdater::insertDef(MemoryDef *MD, bool RenameUses) {
if (NewPhiSize)
tryRemoveTrivialPhis(ArrayRef<WeakVH>(&InsertedPHIs[NewPhiIndex], NewPhiSize));
- // Now that all fixups are done, rename all uses if we are asked.
- if (RenameUses) {
+ // Now that all fixups are done, rename all uses if we are asked. Skip
+ // renaming for defs in unreachable blocks.
+ BasicBlock *StartBlock = MD->getBlock();
+ if (RenameUses && MSSA->getDomTree().getNode(StartBlock)) {
SmallPtrSet<BasicBlock *, 16> Visited;
- BasicBlock *StartBlock = MD->getBlock();
// We are guaranteed there is a def in the block, because we just got it
// handed to us in this function.
MemoryAccess *FirstDef = &*MSSA->getWritableBlockDefs(StartBlock)->begin();
diff --git a/llvm/test/Transforms/GVN/preserve-memoryssa.ll b/llvm/test/Transforms/GVN/preserve-memoryssa.ll
index d9dc9b311e94..b78aba2238e4 100644
--- a/llvm/test/Transforms/GVN/preserve-memoryssa.ll
+++ b/llvm/test/Transforms/GVN/preserve-memoryssa.ll
@@ -141,6 +141,38 @@ define i32 @test_assume_false_to_store_undef_3(i32* %ptr, i32* %ptr.2) {
ret i32 %lv
}
+; Test case for PR48616.
+define void @rename_unreachable_block(i1 %c) personality i32 (...)* undef {
+; CHECK-LABEL: @rename_unreachable_block(
+; CHECK-NEXT: ret void
+; CHECK: bb1:
+; CHECK-NEXT: [[LP:%.*]] = landingpad { i8*, i32 }
+; CHECK-NEXT: cleanup
+; CHECK-NEXT: ret void
+; CHECK: bb2:
+; CHECK-NEXT: invoke void @f()
+; CHECK-NEXT: to label [[BB4:%.*]] unwind label [[BB1:%.*]]
+; CHECK: bb4:
+; CHECK-NEXT: unreachable
+;
+ ret void
+
+bb1:
+ %lp = landingpad { i8*, i32 }
+ cleanup
+ ret void
+
+bb2:
+ br i1 %c, label %bb3, label %bb3
+
+bb3:
+ invoke void @f()
+ to label %bb4 unwind label %bb1
+
+bb4:
+ unreachable
+}
+
declare void @f()
declare void @llvm.assume(i1 noundef) #0
More information about the llvm-branch-commits
mailing list