From c209b88dd438747a39bb16fb99e55703df7b5e54 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Sat, 19 Dec 2020 16:18:04 +0300 Subject: [PATCH] [SimplifyCFG] Teach simplifyCommonResume() to preserve DomTree --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 12 +++++++++--- llvm/test/Transforms/SimplifyCFG/X86/bug-25299.ll | 2 +- llvm/test/Transforms/SimplifyCFG/invoke_unwind_lifetime.ll | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 0e7a8a7..ced2b68 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -4159,7 +4159,7 @@ bool SimplifyCFGOpt::simplifyCommonResume(ResumeInst *RI) { for (pred_iterator PI = pred_begin(TrivialBB), PE = pred_end(TrivialBB); PI != PE;) { BasicBlock *Pred = *PI++; - removeUnwindEdge(Pred); + removeUnwindEdge(Pred, DTU); ++NumInvokes; } @@ -4170,11 +4170,17 @@ bool SimplifyCFGOpt::simplifyCommonResume(ResumeInst *RI) { // predecessors. TrivialBB->getTerminator()->eraseFromParent(); new UnreachableInst(RI->getContext(), TrivialBB); + if (DTU) + DTU->applyUpdatesPermissive({{DominatorTree::Delete, TrivialBB, BB}}); } // Delete the resume block if all its predecessors have been removed. - if (pred_empty(BB)) - BB->eraseFromParent(); + if (pred_empty(BB)) { + if (DTU) + DTU->deleteBB(BB); + else + BB->eraseFromParent(); + } return !TrivialUnwindBlocks.empty(); } diff --git a/llvm/test/Transforms/SimplifyCFG/X86/bug-25299.ll b/llvm/test/Transforms/SimplifyCFG/X86/bug-25299.ll index 706afbe..294c593 100644 --- a/llvm/test/Transforms/SimplifyCFG/X86/bug-25299.ll +++ b/llvm/test/Transforms/SimplifyCFG/X86/bug-25299.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -simplifycfg -S | FileCheck %s +; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s ;; Test case for bug 25299, contributed by David Majnemer. diff --git a/llvm/test/Transforms/SimplifyCFG/invoke_unwind_lifetime.ll b/llvm/test/Transforms/SimplifyCFG/invoke_unwind_lifetime.ll index a498976..c758826 100644 --- a/llvm/test/Transforms/SimplifyCFG/invoke_unwind_lifetime.ll +++ b/llvm/test/Transforms/SimplifyCFG/invoke_unwind_lifetime.ll @@ -1,5 +1,5 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; RUN: opt < %s -simplifycfg -S | FileCheck %s +; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s declare void @llvm.lifetime.start.p0i8(i64, i8*) declare void @llvm.lifetime.end.p0i8(i64, i8*) -- 2.7.4