diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp --- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp +++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp @@ -240,18 +240,9 @@ // 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'. + return isa(F.getEntryBlock().getTerminator()); } static void computeFunctionSummary( diff --git a/llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll b/llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll --- a/llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll +++ b/llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll @@ -34,9 +34,6 @@ define hidden void @_ZN7Derived1xEv(%class.Derived* nonnull align 8 dereferenceable(8) %this) unnamed_addr align 2 { entry: - %this.addr = alloca %class.Derived*, align 8 - store %class.Derived* %this, %class.Derived** %this.addr, align 8 - %this1 = load %class.Derived*, %class.Derived** %this.addr, align 8 %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0)) ret void } @@ -72,34 +69,25 @@ define linkonce_odr hidden void @_ZN7DerivedD2Ev(%class.Derived* nonnull align 8 dereferenceable(8) %this) unnamed_addr comdat align 2 { entry: - %this.addr = alloca %class.Derived*, align 8 - store %class.Derived* %this, %class.Derived** %this.addr, align 8 - %this1 = load %class.Derived*, %class.Derived** %this.addr, align 8 - %0 = bitcast %class.Derived* %this1 to i32 (...)*** + %0 = bitcast %class.Derived* %this to i32 (...)*** store i32 (...)** bitcast (i8** getelementptr inbounds ({ [5 x i8*] }, { [5 x i8*] }* @_ZTV7Derived, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 (...)*** %0, align 8 %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0)) - %1 = bitcast %class.Derived* %this1 to %class.Base* + %1 = bitcast %class.Derived* %this to %class.Base* call void @_ZN4BaseD2Ev(%class.Base* nonnull align 8 dereferenceable(8) %1) ret void } define linkonce_odr hidden void @_ZN7DerivedD0Ev(%class.Derived* nonnull align 8 dereferenceable(8) %this) unnamed_addr comdat align 2 { entry: - %this.addr = alloca %class.Derived*, align 8 - store %class.Derived* %this, %class.Derived** %this.addr, align 8 - %this1 = load %class.Derived*, %class.Derived** %this.addr, align 8 - call void @_ZN7DerivedD2Ev(%class.Derived* nonnull align 8 dereferenceable(8) %this1) - %0 = bitcast %class.Derived* %this1 to i8* + call void @_ZN7DerivedD2Ev(%class.Derived* nonnull align 8 dereferenceable(8) %this) + %0 = bitcast %class.Derived* %this to i8* call void @_ZdlPv(i8* %0) ret void } define linkonce_odr hidden void @_ZN4BaseD2Ev(%class.Base* nonnull align 8 dereferenceable(8) %this) unnamed_addr comdat align 2 { entry: - %this.addr = alloca %class.Base*, align 8 - store %class.Base* %this, %class.Base** %this.addr, align 8 - %this1 = load %class.Base*, %class.Base** %this.addr, align 8 - %0 = bitcast %class.Base* %this1 to i32 (...)*** + %0 = bitcast %class.Base* %this to i32 (...)*** store i32 (...)** bitcast (i8** getelementptr inbounds ({ [5 x i8*] }, { [5 x i8*] }* @_ZTV4Base, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 (...)*** %0, align 8 %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0)) ret void @@ -107,9 +95,6 @@ define linkonce_odr hidden void @_ZN4BaseD0Ev(%class.Base* nonnull align 8 dereferenceable(8) %this) unnamed_addr comdat align 2 { entry: - %this.addr = alloca %class.Base*, align 8 - store %class.Base* %this, %class.Base** %this.addr, align 8 - %this1 = load %class.Base*, %class.Base** %this.addr, align 8 call void @llvm.trap() unreachable } @@ -120,13 +105,10 @@ declare dso_local void @_ZdlPv(i8*) -!llvm.module.flags = !{!5, !6, !7, !8} +!llvm.module.flags = !{!5} !0 = !{i64 16, !"_ZTS4Base"} !1 = !{i64 32, !"_ZTSM4BaseFvvE.virtual"} !2 = !{i64 16, !"_ZTS7Derived"} !3 = !{i64 32, !"_ZTSM7DerivedFvvE.virtual"} !4 = !{i64 1} -!5 = !{i32 1, !"wchar_size", i32 4} -!6 = !{i32 1, !"Virtual Function Elim", i32 0} -!7 = !{i32 7, !"uwtable", i32 1} -!8 = !{i32 7, !"frame-pointer", i32 2} +!5 = !{i32 1, !"Virtual Function Elim", i32 0} diff --git a/llvm/test/ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll b/llvm/test/ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll --- a/llvm/test/ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll +++ b/llvm/test/ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll @@ -102,12 +102,9 @@ define linkonce_odr hidden void @_ZN7DerivedC2Ev(%class.Derived* nonnull align 8 dereferenceable(8) %this) unnamed_addr comdat align 2 { entry: - %this.addr = alloca %class.Derived*, align 8 - store %class.Derived* %this, %class.Derived** %this.addr, align 8 - %this1 = load %class.Derived*, %class.Derived** %this.addr, align 8 - %0 = bitcast %class.Derived* %this1 to %class.Base* + %0 = bitcast %class.Derived* %this to %class.Base* call void @_ZN4BaseC2Ev(%class.Base* nonnull align 8 dereferenceable(8) %0) - %1 = bitcast %class.Derived* %this1 to i32 (...)*** + %1 = bitcast %class.Derived* %this to i32 (...)*** store i32 (...)** bitcast (i8** getelementptr inbounds ({ [5 x i8*] }, { [5 x i8*] }* @_ZTV7Derived, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 (...)*** %1, align 8 ret void } @@ -116,20 +113,14 @@ define linkonce_odr hidden void @_ZN4BaseC2Ev(%class.Base* nonnull align 8 dereferenceable(8) %this) unnamed_addr comdat align 2 { entry: - %this.addr = alloca %class.Base*, align 8 - store %class.Base* %this, %class.Base** %this.addr, align 8 - %this1 = load %class.Base*, %class.Base** %this.addr, align 8 - %0 = bitcast %class.Base* %this1 to i32 (...)*** + %0 = bitcast %class.Base* %this to i32 (...)*** store i32 (...)** bitcast (i8** getelementptr inbounds ({ [5 x i8*] }, { [5 x i8*] }* @_ZTV4Base, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 (...)*** %0, align 8 ret void } define linkonce_odr hidden void @_ZN4BaseD2Ev(%class.Base* nonnull align 8 dereferenceable(8) %this) unnamed_addr comdat align 2 { entry: - %this.addr = alloca %class.Base*, align 8 - store %class.Base* %this, %class.Base** %this.addr, align 8 - %this1 = load %class.Base*, %class.Base** %this.addr, align 8 - %0 = bitcast %class.Base* %this1 to i32 (...)*** + %0 = bitcast %class.Base* %this to i32 (...)*** store i32 (...)** bitcast (i8** getelementptr inbounds ({ [5 x i8*] }, { [5 x i8*] }* @_ZTV4Base, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 (...)*** %0, align 8 %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0)) ret void @@ -137,9 +128,6 @@ define linkonce_odr hidden void @_ZN4BaseD0Ev(%class.Base* nonnull align 8 dereferenceable(8) %this) unnamed_addr comdat align 2 { entry: - %this.addr = alloca %class.Base*, align 8 - store %class.Base* %this, %class.Base** %this.addr, align 8 - %this1 = load %class.Base*, %class.Base** %this.addr, align 8 call void @llvm.trap() unreachable } @@ -150,12 +138,9 @@ declare void @llvm.trap() -!llvm.module.flags = !{!3, !4, !5, !6} +!llvm.module.flags = !{!3} !0 = !{i64 16, !"_ZTS4Base"} !1 = !{i64 32, !"_ZTSM4BaseFvvE.virtual"} !2 = !{i64 1} -!3 = !{i32 1, !"wchar_size", i32 4} -!4 = !{i32 1, !"Virtual Function Elim", i32 0} -!5 = !{i32 7, !"uwtable", i32 1} -!6 = !{i32 7, !"frame-pointer", i32 2} +!3 = !{i32 1, !"Virtual Function Elim", i32 0}