From e0db533febf4af42a5fd5af9bdbc3f6c6d043523 Mon Sep 17 00:00:00 2001 From: Taewook Oh Date: Thu, 5 Apr 2018 04:16:23 +0000 Subject: [CallSiteSplitting] Do not perform callsite splitting inside landing pad Summary: If the callsite is inside landing pad, do not perform callsite splitting. Callsite splitting uses utility function llvm::DuplicateInstructionsInSplitBetween, which eventually calls llvm::SplitEdge. llvm::SplitEdge calls llvm::SplitCriticalEdge with an assumption that the function returns nullptr only when the target edge is not a critical edge (and further assumes that if the return value was not nullptr, the predecessor of the original target edge always has a single successor because critical edge splitting was successful). However, this assumtion is not true because SplitCriticalEdge returns nullptr if the destination block is a landing pad. This invalid assumption results assertion failure. Fundamental solution might be fixing llvm::SplitEdge to not to rely on the invalid assumption. However, it'll involve a lot of work because current API assumes that llvm::SplitEdge never fails. Instead, this patch makes callsite splitting to not to attempt splitting if the callsite is in a landing pad. Attached test case will crash with assertion failure without the fix. Reviewers: fhahn, junbuml, dberlin Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D45130 llvm-svn: 329250 --- llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp b/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp index 796177b5f85..2a29c08a655 100644 --- a/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp +++ b/llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp @@ -206,6 +206,12 @@ static bool canSplitCallSite(CallSite CS, TargetTransformInfo &TTI) { isa(Preds[1]->getTerminator())) return false; + // Do not split a call-site in an exception handling block. This check + // prevents triggering an assertion in SplitEdge used via + // DuplicateInstructionsInSplitBetween. + if (CallSiteBB->isEHPad()) + return false; + return CallSiteBB->canSplitPredecessors(); } -- cgit v1.2.3