@@ -234,6 +234,26 @@ static bool isNonVolatileStore(const Instruction *I) {
234234 return false ;
235235}
236236
237+ // Returns true if `F` must be an unreachable function.
238+ //
239+ // Note if this helper function returns true, `F` is guaranteed
240+ // to be unreachable; if it returns false, `F` might still
241+ // be unreachable but not covered by this helper function.
242+ static bool mustBeUnreachableFunction (const Function &F) {
243+ if (!F.empty ()) {
244+ const BasicBlock &entryBlock = F.getEntryBlock ();
245+ // A function must be unreachable if its entry block
246+ // ends with an 'unreachable'.
247+ if (!entryBlock.empty ()) {
248+ const Instruction *inst = &(*entryBlock.rbegin ());
249+ if (inst->getOpcode () == Instruction::Unreachable) {
250+ return true ;
251+ }
252+ }
253+ }
254+ return false ;
255+ }
256+
237257static void computeFunctionSummary (
238258 ModuleSummaryIndex &Index, const Module &M, const Function &F,
239259 BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, DominatorTree &DT,
@@ -488,7 +508,8 @@ static void computeFunctionSummary(
488508 // Don't try to import functions with noinline attribute.
489509 F.getAttributes ().hasFnAttr (Attribute::NoInline),
490510 F.hasFnAttribute (Attribute::AlwaysInline),
491- F.hasFnAttribute (Attribute::NoUnwind), MayThrow, HasUnknownCall};
511+ F.hasFnAttribute (Attribute::NoUnwind), MayThrow, HasUnknownCall,
512+ mustBeUnreachableFunction (F)};
492513 std::vector<FunctionSummary::ParamAccess> ParamAccesses;
493514 if (auto *SSI = GetSSICallback (F))
494515 ParamAccesses = SSI->getParamAccesses (Index);
@@ -737,7 +758,8 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex(
737758 F->hasFnAttribute (Attribute::AlwaysInline),
738759 F->hasFnAttribute (Attribute::NoUnwind),
739760 /* MayThrow */ true ,
740- /* HasUnknownCall */ true },
761+ /* HasUnknownCall */ true ,
762+ /* MustBeUnreachable */ false },
741763 /* EntryCount=*/ 0 , ArrayRef<ValueInfo>{},
742764 ArrayRef<FunctionSummary::EdgeTy>{},
743765 ArrayRef<GlobalValue::GUID>{},
0 commit comments