[llvm] cf9e61a - [LTO][WPD] Simplify mustBeUnreachableFunction and test after D115492

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 15 15:43:40 PST 2021


Author: Fangrui Song
Date: 2021-12-15T15:43:35-08:00
New Revision: cf9e61a9bb61605e3c78f5d10ae8a3bcb6d8865a

URL: https://github.com/llvm/llvm-project/commit/cf9e61a9bb61605e3c78f5d10ae8a3bcb6d8865a
DIFF: https://github.com/llvm/llvm-project/commit/cf9e61a9bb61605e3c78f5d10ae8a3bcb6d8865a.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
    llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll
    llvm/test/ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index 4039a443cc4d..2880ca62a7f8 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<UnreachableInst>(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
index e8603054dff7..91ba2e44f7f7 100644
--- 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 @@ $_ZTV4Base = comdat any
 
 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 @@ declare void @llvm.assume(i1 noundef)
 
 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 @@ entry:
 
 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 void @llvm.trap()
 
 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
index c878a9f13fe5..3c4cf335fa6e 100644
--- 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 @@ declare dso_local nonnull i8* @_Znwm(i64)
 
 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 @@ declare dso_local void @_Z3fooP4Base(%class.Base*)
 
 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 @@ entry:
 
 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 dso_local i32 @printf(i8*, ...)
 
 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}


        


More information about the llvm-commits mailing list