From cf9e61a9bb61605e3c78f5d10ae8a3bcb6d8865a Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 15 Dec 2021 15:43:35 -0800 Subject: [LTO][WPD] Simplify mustBeUnreachableFunction and test after D115492 An well-formed IR function definition must have an entry basic block and a well-formed IR basic block must have one terminator so the emptiness check can be simplified. Also simplify the test a bit. Reviewed By: luna Differential Revision: https://reviews.llvm.org/D115780 --- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'llvm/lib/Analysis/ModuleSummaryAnalysis.cpp') diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp index 4039a44..2880ca6 100644 --- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp +++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp @@ -234,24 +234,16 @@ static bool isNonVolatileStore(const Instruction *I) { return false; } -// Returns true if `F` must be an unreachable function. +// Returns true if the function definition must be unreachable. // // Note if this helper function returns true, `F` is guaranteed // to be unreachable; if it returns false, `F` might still // be unreachable but not covered by this helper function. static bool mustBeUnreachableFunction(const Function &F) { - if (!F.empty()) { - const BasicBlock &entryBlock = F.getEntryBlock(); - // A function must be unreachable if its entry block - // ends with an 'unreachable'. - if (!entryBlock.empty()) { - const Instruction *inst = &(*entryBlock.rbegin()); - if (inst->getOpcode() == Instruction::Unreachable) { - return true; - } - } - } - return false; + // A function must be unreachable if its entry block ends with an + // 'unreachable'. + assert(!F.isDeclaration()); + return isa(F.getEntryBlock().getTerminator()); } static void computeFunctionSummary( -- cgit v1.1