[PATCH] D115648: [LTO] Ignore unreachable virtual functions in WPD in thin LTO

2021-12-15 Thread Mingming Liu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4ab5527c15f0: [ThinLTO] Ignore unreachable virtual functions 
in WPD in thin LTO. (authored by luna).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115648/new/

https://reviews.llvm.org/D115648

Files:
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/ThinLTO/X86/Inputs/devirt_after_filtering_unreachable_lib.ll
  llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll
  llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
  llvm/test/ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll

Index: llvm/test/ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll
===
--- llvm/test/ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll
+++ /dev/null
@@ -1,146 +0,0 @@
-; Test that unreachable functions are ignored by WPD in hybrid LTO.
-; In this test case, the unreachable function is the virtual deleting destructor of an abstract class.
-
-; Generate split module with summary for hybrid Regular LTO WPD
-; RUN: opt -thinlto-bc -thinlto-split-lto-unit %s -o %t-main.bc
-; RUN: opt -thinlto-bc -thinlto-split-lto-unit %p/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll -o %t-foo.bc
-; Tests that devirtualization happens.
-; RUN: llvm-lto2 run -save-temps %t-main.bc %t-foo.bc -pass-remarks=. -o %t \
-; RUN:   -whole-program-visibility \
-; RUN:   -r=%t-foo.bc,_ZN7Derived1xEv,pl \
-; RUN:   -r=%t-foo.bc,printf, \
-; RUN:   -r=%t-foo.bc,_Z3fooP4Base,pl \
-; RUN:   -r=%t-foo.bc,_ZN7DerivedD2Ev,pl \
-; RUN:   -r=%t-foo.bc,_ZN7DerivedD0Ev,pl \
-; RUN:   -r=%t-foo.bc,_ZN4BaseD2Ev,pl \
-; RUN:   -r=%t-foo.bc,_ZN4BaseD0Ev,pl \
-; RUN:   -r=%t-foo.bc,__cxa_pure_virtual, \
-; RUN:   -r=%t-foo.bc,_ZdlPv, \
-; RUN:   -r=%t-foo.bc,_ZTV7Derived,l \
-; RUN:   -r=%t-foo.bc,_ZTVN10__cxxabiv120__si_class_type_infoE, \
-; RUN:   -r=%t-foo.bc,_ZTS7Derived,pl \
-; RUN:   -r=%t-foo.bc,_ZTVN10__cxxabiv117__class_type_infoE, \
-; RUN:   -r=%t-foo.bc,_ZTS4Base,pl \
-; RUN:   -r=%t-foo.bc,_ZTI4Base,pl \
-; RUN:   -r=%t-foo.bc,_ZTI7Derived,pl \
-; RUN:   -r=%t-foo.bc,_ZTV4Base,l \
-; RUN:   -r=%t-foo.bc,__cxa_pure_virtual, \
-; RUN:   -r=%t-foo.bc,_ZN7Derived1xEv, \
-; RUN:   -r=%t-foo.bc,_ZN7DerivedD2Ev, \
-; RUN:   -r=%t-foo.bc,_ZN7DerivedD0Ev, \
-; RUN:   -r=%t-foo.bc,_ZN4BaseD2Ev, \
-; RUN:   -r=%t-foo.bc,_ZN4BaseD0Ev, \
-; RUN:   -r=%t-foo.bc,_ZTV7Derived,pl \
-; RUN:   -r=%t-foo.bc,_ZTI4Base, \
-; RUN:   -r=%t-foo.bc,_ZTI7Derived, \
-; RUN:   -r=%t-foo.bc,_ZTV4Base,pl \
-; RUN:   -r=%t-main.bc,main,plx \
-; RUN:   -r=%t-main.bc,_Znwm,pl \
-; RUN:   -r=%t-main.bc,_ZN7DerivedC2Ev,pl \
-; RUN:   -r=%t-main.bc,_Z3fooP4Base, \
-; RUN:   -r=%t-main.bc,_ZN4BaseC2Ev,pl \
-; RUN:   -r=%t-main.bc,_ZN4BaseD2Ev, \
-; RUN:   -r=%t-main.bc,_ZN4BaseD0Ev, \
-; RUN:   -r=%t-main.bc,__cxa_pure_virtual, \
-; RUN:   -r=%t-main.bc,printf, \
-; RUN:   -r=%t-main.bc,_ZTV7Derived, \
-; RUN:   -r=%t-main.bc,_ZTV4Base, \
-; RUN:   -r=%t-main.bc,_ZTVN10__cxxabiv117__class_type_infoE, \
-; RUN:   -r=%t-main.bc,_ZTS4Base, \
-; RUN:   -r=%t-main.bc,_ZTI4Base, \
-; RUN:   -r=%t-main.bc,__cxa_pure_virtual, \
-; RUN:   -r=%t-main.bc,_ZN4BaseD2Ev, \
-; RUN:   -r=%t-main.bc,_ZN4BaseD0Ev, \
-; RUN:   -r=%t-main.bc,_ZTV4Base, \
-; RUN:   -r=%t-main.bc,_ZTI4Base, 2>&1 | FileCheck %s --check-prefix=REMARK
- 
-; REMARK-COUNT-1: single-impl: devirtualized a call to _ZN7DerivedD0Ev
-
-; ModuleID = 'tmp.cc'
-source_filename = "tmp.cc"
-target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-unknown-linux-gnu"
-
-%class.Derived = type { %class.Base }
-%class.Base = type { i32 (...)** }
-
-$_ZN7DerivedC2Ev = comdat any
-
-$_ZN4BaseC2Ev = comdat any
-
-$_ZN4BaseD2Ev = comdat any
-
-$_ZN4BaseD0Ev = comdat any
-
-$_ZTV4Base = comdat any
-
-$_ZTS4Base = comdat any
-
-$_ZTI4Base = comdat any
-
-@_ZTV7Derived = external dso_local unnamed_addr constant { [5 x i8*] }, align 8
-@_ZTV4Base = linkonce_odr hidden unnamed_addr constant { [5 x i8*] } { [5 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI4Base to i8*), i8* bitcast (void (%class.Base*)* @_ZN4BaseD2Ev to i8*), i8* bitcast (void (%class.Base*)* @_ZN4BaseD0Ev to i8*), i8* bitcast (void ()* @__cxa_pure_virtual to i8*)] }, comdat, align 8, !type !0, !type !1, !vcall_visibility !2
-@_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global i8*
-@_ZTS4Base = linkonce_odr hidden constant [6 x i8] c"4Base\00", comdat, align 1
-@_ZTI4Base = linkonce_odr hidden constant { i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv117__class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @_ZTS4Base, i32 0, i32 0) }, comdat, align 8
-@.str = private unnamed_addr constant [18 x i8] c"In Base::~Base()\0A\00", align 

[PATCH] D115648: [LTO] Ignore unreachable virtual functions in WPD in thin LTO

2021-12-15 Thread Mingming Liu via Phabricator via cfe-commits
luna added a comment.

In D115648#3196142 , @luna wrote:

> Simplify test case by using `-O3` to generate IR.

Probably because of the diff from 
`ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll` to 
`ThinLTO/X86/devirt_after_filtering_unreachable.ll` is big, `git` regard a `git 
mv` as `git add` and `git mv` here (this stack overflow 
)
 question echoes.

So I'm going to keep it (without trying to make it look like a `mv`), wait for 
the pre-merge test and the local `ninja check-llvm-lto`, and then land this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115648/new/

https://reviews.llvm.org/D115648

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115648: [LTO] Ignore unreachable virtual functions in WPD in thin LTO

2021-12-15 Thread Mingming Liu via Phabricator via cfe-commits
luna updated this revision to Diff 394689.
luna marked an inline comment as done.
luna added a comment.

Simplify test case by using `-O3` to generate IR.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115648/new/

https://reviews.llvm.org/D115648

Files:
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/ThinLTO/X86/Inputs/devirt_after_filtering_unreachable_lib.ll
  llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll
  llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
  llvm/test/ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll

Index: llvm/test/ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll
===
--- llvm/test/ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll
+++ /dev/null
@@ -1,146 +0,0 @@
-; Test that unreachable functions are ignored by WPD in hybrid LTO.
-; In this test case, the unreachable function is the virtual deleting destructor of an abstract class.
-
-; Generate split module with summary for hybrid Regular LTO WPD
-; RUN: opt -thinlto-bc -thinlto-split-lto-unit %s -o %t-main.bc
-; RUN: opt -thinlto-bc -thinlto-split-lto-unit %p/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll -o %t-foo.bc
-; Tests that devirtualization happens.
-; RUN: llvm-lto2 run -save-temps %t-main.bc %t-foo.bc -pass-remarks=. -o %t \
-; RUN:   -whole-program-visibility \
-; RUN:   -r=%t-foo.bc,_ZN7Derived1xEv,pl \
-; RUN:   -r=%t-foo.bc,printf, \
-; RUN:   -r=%t-foo.bc,_Z3fooP4Base,pl \
-; RUN:   -r=%t-foo.bc,_ZN7DerivedD2Ev,pl \
-; RUN:   -r=%t-foo.bc,_ZN7DerivedD0Ev,pl \
-; RUN:   -r=%t-foo.bc,_ZN4BaseD2Ev,pl \
-; RUN:   -r=%t-foo.bc,_ZN4BaseD0Ev,pl \
-; RUN:   -r=%t-foo.bc,__cxa_pure_virtual, \
-; RUN:   -r=%t-foo.bc,_ZdlPv, \
-; RUN:   -r=%t-foo.bc,_ZTV7Derived,l \
-; RUN:   -r=%t-foo.bc,_ZTVN10__cxxabiv120__si_class_type_infoE, \
-; RUN:   -r=%t-foo.bc,_ZTS7Derived,pl \
-; RUN:   -r=%t-foo.bc,_ZTVN10__cxxabiv117__class_type_infoE, \
-; RUN:   -r=%t-foo.bc,_ZTS4Base,pl \
-; RUN:   -r=%t-foo.bc,_ZTI4Base,pl \
-; RUN:   -r=%t-foo.bc,_ZTI7Derived,pl \
-; RUN:   -r=%t-foo.bc,_ZTV4Base,l \
-; RUN:   -r=%t-foo.bc,__cxa_pure_virtual, \
-; RUN:   -r=%t-foo.bc,_ZN7Derived1xEv, \
-; RUN:   -r=%t-foo.bc,_ZN7DerivedD2Ev, \
-; RUN:   -r=%t-foo.bc,_ZN7DerivedD0Ev, \
-; RUN:   -r=%t-foo.bc,_ZN4BaseD2Ev, \
-; RUN:   -r=%t-foo.bc,_ZN4BaseD0Ev, \
-; RUN:   -r=%t-foo.bc,_ZTV7Derived,pl \
-; RUN:   -r=%t-foo.bc,_ZTI4Base, \
-; RUN:   -r=%t-foo.bc,_ZTI7Derived, \
-; RUN:   -r=%t-foo.bc,_ZTV4Base,pl \
-; RUN:   -r=%t-main.bc,main,plx \
-; RUN:   -r=%t-main.bc,_Znwm,pl \
-; RUN:   -r=%t-main.bc,_ZN7DerivedC2Ev,pl \
-; RUN:   -r=%t-main.bc,_Z3fooP4Base, \
-; RUN:   -r=%t-main.bc,_ZN4BaseC2Ev,pl \
-; RUN:   -r=%t-main.bc,_ZN4BaseD2Ev, \
-; RUN:   -r=%t-main.bc,_ZN4BaseD0Ev, \
-; RUN:   -r=%t-main.bc,__cxa_pure_virtual, \
-; RUN:   -r=%t-main.bc,printf, \
-; RUN:   -r=%t-main.bc,_ZTV7Derived, \
-; RUN:   -r=%t-main.bc,_ZTV4Base, \
-; RUN:   -r=%t-main.bc,_ZTVN10__cxxabiv117__class_type_infoE, \
-; RUN:   -r=%t-main.bc,_ZTS4Base, \
-; RUN:   -r=%t-main.bc,_ZTI4Base, \
-; RUN:   -r=%t-main.bc,__cxa_pure_virtual, \
-; RUN:   -r=%t-main.bc,_ZN4BaseD2Ev, \
-; RUN:   -r=%t-main.bc,_ZN4BaseD0Ev, \
-; RUN:   -r=%t-main.bc,_ZTV4Base, \
-; RUN:   -r=%t-main.bc,_ZTI4Base, 2>&1 | FileCheck %s --check-prefix=REMARK
- 
-; REMARK-COUNT-1: single-impl: devirtualized a call to _ZN7DerivedD0Ev
-
-; ModuleID = 'tmp.cc'
-source_filename = "tmp.cc"
-target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-unknown-linux-gnu"
-
-%class.Derived = type { %class.Base }
-%class.Base = type { i32 (...)** }
-
-$_ZN7DerivedC2Ev = comdat any
-
-$_ZN4BaseC2Ev = comdat any
-
-$_ZN4BaseD2Ev = comdat any
-
-$_ZN4BaseD0Ev = comdat any
-
-$_ZTV4Base = comdat any
-
-$_ZTS4Base = comdat any
-
-$_ZTI4Base = comdat any
-
-@_ZTV7Derived = external dso_local unnamed_addr constant { [5 x i8*] }, align 8
-@_ZTV4Base = linkonce_odr hidden unnamed_addr constant { [5 x i8*] } { [5 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI4Base to i8*), i8* bitcast (void (%class.Base*)* @_ZN4BaseD2Ev to i8*), i8* bitcast (void (%class.Base*)* @_ZN4BaseD0Ev to i8*), i8* bitcast (void ()* @__cxa_pure_virtual to i8*)] }, comdat, align 8, !type !0, !type !1, !vcall_visibility !2
-@_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global i8*
-@_ZTS4Base = linkonce_odr hidden constant [6 x i8] c"4Base\00", comdat, align 1
-@_ZTI4Base = linkonce_odr hidden constant { i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv117__class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @_ZTS4Base, i32 0, i32 0) }, comdat, align 8
-@.str = private unnamed_addr constant [18 x i8] c"In Base::~Base()\0A\00", align 1
-
-define hidden i32 @main() {
-entry:
-  %d = alloca %class.Derived*, align 8
-  %call = 

[PATCH] D115648: [LTO] Ignore unreachable virtual functions in WPD in thin LTO

2021-12-14 Thread Mingming Liu via Phabricator via cfe-commits
luna marked an inline comment as done.
luna added a comment.

thanks for the inputs!




Comment at: llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll:16
+
+; ENABLESPLITFLAG: gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} 
mustBeUnreachable: 1
+

tejohnson wrote:
> I think it can be shared with the equivalent checks in the unsplit case as 
> well. And probably with a check-prefix name that reflects what is being 
> checked (e.g. UNREACHABLEFLAG), or maybe something simpler (e.g. FLAG).
Use UNREACHABLEFLAG and share it across split and unsplit case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115648/new/

https://reviews.llvm.org/D115648

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115648: [LTO] Ignore unreachable virtual functions in WPD in thin LTO

2021-12-14 Thread Mingming Liu via Phabricator via cfe-commits
luna updated this revision to Diff 394461.
luna added a comment.

Simplify filecheck by re-using one prefix to test the unreachable bit.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115648/new/

https://reviews.llvm.org/D115648

Files:
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/ThinLTO/X86/Inputs/devirt_after_filtering_unreachable_lib.ll
  llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll
  llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
  llvm/test/ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll

Index: llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
===
--- llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
+++ llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
@@ -1,9 +1,18 @@
-; Test that unreachable functions are ignored by WPD in hybrid LTO.
+; Test that unreachable functions are ignored by WPD in hybrid LTO, and thin LTO.
 ; In this test case, the unreachable function is the virtual deleting destructor of an abstract class.
 
 ; Generate split module with summary for hybrid Regular LTO WPD
 ; RUN: opt -thinlto-bc -thinlto-split-lto-unit %s -o %t-main.bc
-; RUN: opt -thinlto-bc -thinlto-split-lto-unit %p/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll -o %t-foo.bc
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit %p/Inputs/devirt_after_filtering_unreachable_lib.ll -o %t-foo.bc
+
+; Check that deleting destructor of pure virtual class is unreachable.
+; RUN: llvm-modextract -b -n=0 %t-main.bc -o %t-main.bc.0
+; RUN: llvm-dis -o - %t-main.bc.0 | FileCheck %s --check-prefix=UNREACHABLEFLAG
+
+; Check that deleting destructor of pure virtual class is unreachable.
+; RUN: llvm-modextract -b -n=0 %t-foo.bc -o %t-foo.bc.0
+; RUN: llvm-dis -o - %t-foo.bc.0 | FileCheck %s --check-prefix=UNREACHABLEFLAG
+
 ; Tests that devirtualization happens.
 ; RUN: llvm-lto2 run -save-temps %t-main.bc %t-foo.bc -pass-remarks=. -o %t \
 ; RUN:   -whole-program-visibility \
@@ -56,6 +65,59 @@
  
 ; REMARK-COUNT-1: single-impl: devirtualized a call to _ZN7DerivedD0Ev
 
+; Generate unsplit module with summary for ThinLTO index-based WPD.
+; RUN: opt -thinlto-bc -o %t3.o %s
+
+; Check that deleting destructor of pure virtual class is unreachable.
+; RUN: llvm-dis -o - %t3.o | FileCheck %s --check-prefix=UNREACHABLEFLAG
+
+; Check that deleting destructor of pure virtual class is unreachable.
+; RUN: opt -thinlto-bc -o %t4.o %p/Inputs/devirt_after_filtering_unreachable_lib.ll
+; RUN: llvm-dis -o - %t4.o | FileCheck %s --check-prefix=UNREACHABLEFLAG
+
+; UNREACHABLEFLAG: gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} mustBeUnreachable: 1
+
+; Test that devirtualized happen in index based WPD
+; RUN: llvm-lto2 run %t4.o %t3.o -save-temps -pass-remarks=. \
+; RUN:   -whole-program-visibility \
+; RUN:   -wholeprogramdevirt-print-index-based \
+; RUN:   -o %t5 \
+; RUN:   -r=%t4.o,_ZN7Derived1xEv,pl \
+; RUN:   -r=%t4.o,printf, \
+; RUN:   -r=%t4.o,_Z3fooP4Base,pl \
+; RUN:   -r=%t4.o,_ZN7DerivedD2Ev,pl \
+; RUN:   -r=%t4.o,_ZN7DerivedD0Ev,pl \
+; RUN:   -r=%t4.o,_ZN4BaseD2Ev,pl \
+; RUN:   -r=%t4.o,_ZN4BaseD0Ev,pl \
+; RUN:   -r=%t4.o,__cxa_pure_virtual, \
+; RUN:   -r=%t4.o,_ZdlPv, \
+; RUN:   -r=%t4.o,_ZTV7Derived,pl \
+; RUN:   -r=%t4.o,_ZTVN10__cxxabiv120__si_class_type_infoE, \
+; RUN:   -r=%t4.o,_ZTS7Derived,pl \
+; RUN:   -r=%t4.o,_ZTVN10__cxxabiv117__class_type_infoE, \
+; RUN:   -r=%t4.o,_ZTS4Base,pl \
+; RUN:   -r=%t4.o,_ZTI4Base,pl \
+; RUN:   -r=%t4.o,_ZTI7Derived,pl \
+; RUN:   -r=%t4.o,_ZTV4Base,pl \
+; RUN:   -r=%t3.o,main,plx \
+; RUN:   -r=%t3.o,_Znwm, \
+; RUN:   -r=%t3.o,_ZN7DerivedC2Ev,pl \
+; RUN:   -r=%t3.o,_Z3fooP4Base, \
+; RUN:   -r=%t3.o,_ZN4BaseC2Ev,pl \
+; RUN:   -r=%t3.o,_ZN4BaseD2Ev, \
+; RUN:   -r=%t3.o,_ZN4BaseD0Ev, \
+; RUN:   -r=%t3.o,__cxa_pure_virtual, \
+; RUN:   -r=%t3.o,printf, \
+; RUN:   -r=%t3.o,_ZTV7Derived, \
+; RUN:   -r=%t3.o,_ZTV4Base, \
+; RUN:   -r=%t3.o,_ZTVN10__cxxabiv117__class_type_infoE, \
+; RUN:   -r=%t3.o,_ZTS4Base, \
+; RUN:   -r=%t3.o,_ZTI4Base, 2>&1 | FileCheck %s --check-prefix=THINREMARK
+
+; THINREMARK: Devirtualized call to {{.*}} (_ZN7DerivedD0Ev)
+; THINREMARK: single-impl: devirtualized a call to _ZN7DerivedD0Ev
+; THINREMARK: single-impl: devirtualized a call to _ZN7DerivedD0Ev
+
 ; ModuleID = 'tmp.cc'
 source_filename = "tmp.cc"
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
Index: llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll
===
--- /dev/null
+++ llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll
@@ -1,132 +0,0 @@
-; ModuleID = 'lib.cc'
-source_filename = "lib.cc"
-target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
-target triple = 

[PATCH] D115648: [LTO] Ignore unreachable virtual functions in WPD in thin LTO

2021-12-14 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll:16
+
+; ENABLESPLITFLAG: gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} 
mustBeUnreachable: 1
+

I think it can be shared with the equivalent checks in the unsplit case as 
well. And probably with a check-prefix name that reflects what is being checked 
(e.g. UNREACHABLEFLAG), or maybe something simpler (e.g. FLAG).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115648/new/

https://reviews.llvm.org/D115648

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115648: [LTO] Ignore unreachable virtual functions in WPD in thin LTO

2021-12-14 Thread Mingming Liu via Phabricator via cfe-commits
luna added inline comments.



Comment at: llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll:11
+; RUN: llvm-dis -o - %t-main.bc.0 | FileCheck %s --check-prefix=ENABLESPLITFLAG
+; ENABLESPLITFLAG: gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} 
mustBeUnreachable: 1
+

tejohnson wrote:
> You can combine all of these (ENABLESPLITFLAG, LIBENABLESPLITFLAG, etc) now 
> into a single filecheck pattern.
(Saw this after previous reply) Done by sharing the pattern between two 
filecheck lines.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115648/new/

https://reviews.llvm.org/D115648

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115648: [LTO] Ignore unreachable virtual functions in WPD in thin LTO

2021-12-14 Thread Mingming Liu via Phabricator via cfe-commits
luna updated this revision to Diff 394443.
luna marked an inline comment as done.
luna added a comment.

Simplify test by sharing one pattern across two filecheck lines.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115648/new/

https://reviews.llvm.org/D115648

Files:
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/ThinLTO/X86/Inputs/devirt_after_filtering_unreachable_lib.ll
  llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll
  llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
  llvm/test/ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll

Index: llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
===
--- llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
+++ llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
@@ -1,9 +1,20 @@
-; Test that unreachable functions are ignored by WPD in hybrid LTO.
+; Test that unreachable functions are ignored by WPD in hybrid LTO, and thin LTO.
 ; In this test case, the unreachable function is the virtual deleting destructor of an abstract class.
 
 ; Generate split module with summary for hybrid Regular LTO WPD
 ; RUN: opt -thinlto-bc -thinlto-split-lto-unit %s -o %t-main.bc
-; RUN: opt -thinlto-bc -thinlto-split-lto-unit %p/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll -o %t-foo.bc
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit %p/Inputs/devirt_after_filtering_unreachable_lib.ll -o %t-foo.bc
+
+; Check that deleting destructor of pure virtual class is unreachable.
+; RUN: llvm-modextract -b -n=0 %t-main.bc -o %t-main.bc.0
+; RUN: llvm-dis -o - %t-main.bc.0 | FileCheck %s --check-prefix=ENABLESPLITFLAG
+
+; Check that deleting destructor of pure virtual class is unreachable.
+; RUN: llvm-modextract -b -n=0 %t-foo.bc -o %t-foo.bc.0
+; RUN: llvm-dis -o - %t-foo.bc.0 | FileCheck %s --check-prefix=ENABLESPLITFLAG
+
+; ENABLESPLITFLAG: gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} mustBeUnreachable: 1
+
 ; Tests that devirtualization happens.
 ; RUN: llvm-lto2 run -save-temps %t-main.bc %t-foo.bc -pass-remarks=. -o %t \
 ; RUN:   -whole-program-visibility \
@@ -56,6 +67,59 @@
  
 ; REMARK-COUNT-1: single-impl: devirtualized a call to _ZN7DerivedD0Ev
 
+; Generate unsplit module with summary for ThinLTO index-based WPD.
+; RUN: opt -thinlto-bc -o %t3.o %s
+; RUN: opt -thinlto-bc -o %t4.o %p/Inputs/devirt_after_filtering_unreachable_lib.ll
+
+; Check that deleting destructor of pure virtual class is unreachable.
+; RUN: llvm-dis -o - %t3.o | FileCheck %s --check-prefix=NOENABLESPLITFLAG
+; NOENABLESPLITFLAG: gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} mustBeUnreachable: 1
+
+; Check that deleting destructor of pure virtual class is unreachable.
+; RUN: llvm-dis -o - %t4.o | FileCheck %s --check-prefix=LIBNOENABLESPLITFLAG
+; LIBNOENABLESPLITFLAG: gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} mustBeUnreachable: 1
+
+; Test that devirtualized happen in index based WPD
+; RUN: llvm-lto2 run %t4.o %t3.o -save-temps -pass-remarks=. \
+; RUN:   -whole-program-visibility \
+; RUN:   -wholeprogramdevirt-print-index-based \
+; RUN:   -o %t5 \
+; RUN:   -r=%t4.o,_ZN7Derived1xEv,pl \
+; RUN:   -r=%t4.o,printf, \
+; RUN:   -r=%t4.o,_Z3fooP4Base,pl \
+; RUN:   -r=%t4.o,_ZN7DerivedD2Ev,pl \
+; RUN:   -r=%t4.o,_ZN7DerivedD0Ev,pl \
+; RUN:   -r=%t4.o,_ZN4BaseD2Ev,pl \
+; RUN:   -r=%t4.o,_ZN4BaseD0Ev,pl \
+; RUN:   -r=%t4.o,__cxa_pure_virtual, \
+; RUN:   -r=%t4.o,_ZdlPv, \
+; RUN:   -r=%t4.o,_ZTV7Derived,pl \
+; RUN:   -r=%t4.o,_ZTVN10__cxxabiv120__si_class_type_infoE, \
+; RUN:   -r=%t4.o,_ZTS7Derived,pl \
+; RUN:   -r=%t4.o,_ZTVN10__cxxabiv117__class_type_infoE, \
+; RUN:   -r=%t4.o,_ZTS4Base,pl \
+; RUN:   -r=%t4.o,_ZTI4Base,pl \
+; RUN:   -r=%t4.o,_ZTI7Derived,pl \
+; RUN:   -r=%t4.o,_ZTV4Base,pl \
+; RUN:   -r=%t3.o,main,plx \
+; RUN:   -r=%t3.o,_Znwm, \
+; RUN:   -r=%t3.o,_ZN7DerivedC2Ev,pl \
+; RUN:   -r=%t3.o,_Z3fooP4Base, \
+; RUN:   -r=%t3.o,_ZN4BaseC2Ev,pl \
+; RUN:   -r=%t3.o,_ZN4BaseD2Ev, \
+; RUN:   -r=%t3.o,_ZN4BaseD0Ev, \
+; RUN:   -r=%t3.o,__cxa_pure_virtual, \
+; RUN:   -r=%t3.o,printf, \
+; RUN:   -r=%t3.o,_ZTV7Derived, \
+; RUN:   -r=%t3.o,_ZTV4Base, \
+; RUN:   -r=%t3.o,_ZTVN10__cxxabiv117__class_type_infoE, \
+; RUN:   -r=%t3.o,_ZTS4Base, \
+; RUN:   -r=%t3.o,_ZTI4Base, 2>&1 | FileCheck %s --check-prefix=THINREMARK
+
+; THINREMARK: Devirtualized call to {{.*}} (_ZN7DerivedD0Ev)
+; THINREMARK: single-impl: devirtualized a call to _ZN7DerivedD0Ev
+; THINREMARK: single-impl: devirtualized a call to _ZN7DerivedD0Ev
+
 ; ModuleID = 'tmp.cc'
 source_filename = "tmp.cc"
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
Index: llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll
===
--- /dev/null
+++ 

[PATCH] D115648: [LTO] Ignore unreachable virtual functions in WPD in thin LTO

2021-12-14 Thread Mingming Liu via Phabricator via cfe-commits
luna marked an inline comment as done.
luna added a comment.

thanks for review!

Also in the previous reply, I forgot to mention I removed the the line `assert 
((VTP.FuncVI) && "VTP.FuncVI must be nullptr` after finding existing references 
doesn't guarantee that [1], and `mustBeUnreachableFunction` will return false 
if an empty VI is passed in anyway.

I'll run a ninja check (may take a while) and then push this.

[1] For field `VirtFuncOffset::FuncVI`, there are `if` and  `assertions` about 
empty value (e.g., 
https://github.com/llvm/llvm-project/blob/main/llvm/lib/AsmParser/LLParser.cpp#L7834)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115648/new/

https://reviews.llvm.org/D115648

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115648: [LTO] Ignore unreachable virtual functions in WPD in thin LTO

2021-12-14 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll:11
+; RUN: llvm-dis -o - %t-main.bc.0 | FileCheck %s --check-prefix=ENABLESPLITFLAG
+; ENABLESPLITFLAG: gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} 
mustBeUnreachable: 1
+

You can combine all of these (ENABLESPLITFLAG, LIBENABLESPLITFLAG, etc) now 
into a single filecheck pattern.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115648/new/

https://reviews.llvm.org/D115648

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115648: [LTO] Ignore unreachable virtual functions in WPD in thin LTO

2021-12-14 Thread Mingming Liu via Phabricator via cfe-commits
luna updated this revision to Diff 394435.
luna added a comment.

Simplify test by using non-DAG prefix (for one pattern), and avoid capturing 
values since they are not used.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115648/new/

https://reviews.llvm.org/D115648

Files:
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/ThinLTO/X86/Inputs/devirt_after_filtering_unreachable_lib.ll
  llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll
  llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
  llvm/test/ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll

Index: llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
===
--- llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
+++ llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
@@ -1,9 +1,20 @@
-; Test that unreachable functions are ignored by WPD in hybrid LTO.
+; Test that unreachable functions are ignored by WPD in hybrid LTO, and thin LTO.
 ; In this test case, the unreachable function is the virtual deleting destructor of an abstract class.
 
 ; Generate split module with summary for hybrid Regular LTO WPD
 ; RUN: opt -thinlto-bc -thinlto-split-lto-unit %s -o %t-main.bc
-; RUN: opt -thinlto-bc -thinlto-split-lto-unit %p/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll -o %t-foo.bc
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit %p/Inputs/devirt_after_filtering_unreachable_lib.ll -o %t-foo.bc
+
+; Check that deleting destructor of pure virtual class is unreachable.
+; RUN: llvm-modextract -b -n=0 %t-main.bc -o %t-main.bc.0
+; RUN: llvm-dis -o - %t-main.bc.0 | FileCheck %s --check-prefix=ENABLESPLITFLAG
+; ENABLESPLITFLAG: gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} mustBeUnreachable: 1
+
+; Check that deleting destructor of pure virtual class is unreachable.
+; RUN: llvm-modextract -b -n=0 %t-foo.bc -o %t-foo.bc.0
+; RUN: llvm-dis -o - %t-foo.bc.0 | FileCheck %s --check-prefix=LIBENABLESPLITFLAG
+; LIBENABLESPLITFLAG: gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} mustBeUnreachable: 1
+
 ; Tests that devirtualization happens.
 ; RUN: llvm-lto2 run -save-temps %t-main.bc %t-foo.bc -pass-remarks=. -o %t \
 ; RUN:   -whole-program-visibility \
@@ -56,6 +67,59 @@
  
 ; REMARK-COUNT-1: single-impl: devirtualized a call to _ZN7DerivedD0Ev
 
+; Generate unsplit module with summary for ThinLTO index-based WPD.
+; RUN: opt -thinlto-bc -o %t3.o %s
+; RUN: opt -thinlto-bc -o %t4.o %p/Inputs/devirt_after_filtering_unreachable_lib.ll
+
+; Check that deleting destructor of pure virtual class is unreachable.
+; RUN: llvm-dis -o - %t3.o | FileCheck %s --check-prefix=NOENABLESPLITFLAG
+; NOENABLESPLITFLAG: gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} mustBeUnreachable: 1
+
+; Check that deleting destructor of pure virtual class is unreachable.
+; RUN: llvm-dis -o - %t4.o | FileCheck %s --check-prefix=LIBNOENABLESPLITFLAG
+; LIBNOENABLESPLITFLAG: gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} mustBeUnreachable: 1
+
+; Test that devirtualized happen in index based WPD
+; RUN: llvm-lto2 run %t4.o %t3.o -save-temps -pass-remarks=. \
+; RUN:   -whole-program-visibility \
+; RUN:   -wholeprogramdevirt-print-index-based \
+; RUN:   -o %t5 \
+; RUN:   -r=%t4.o,_ZN7Derived1xEv,pl \
+; RUN:   -r=%t4.o,printf, \
+; RUN:   -r=%t4.o,_Z3fooP4Base,pl \
+; RUN:   -r=%t4.o,_ZN7DerivedD2Ev,pl \
+; RUN:   -r=%t4.o,_ZN7DerivedD0Ev,pl \
+; RUN:   -r=%t4.o,_ZN4BaseD2Ev,pl \
+; RUN:   -r=%t4.o,_ZN4BaseD0Ev,pl \
+; RUN:   -r=%t4.o,__cxa_pure_virtual, \
+; RUN:   -r=%t4.o,_ZdlPv, \
+; RUN:   -r=%t4.o,_ZTV7Derived,pl \
+; RUN:   -r=%t4.o,_ZTVN10__cxxabiv120__si_class_type_infoE, \
+; RUN:   -r=%t4.o,_ZTS7Derived,pl \
+; RUN:   -r=%t4.o,_ZTVN10__cxxabiv117__class_type_infoE, \
+; RUN:   -r=%t4.o,_ZTS4Base,pl \
+; RUN:   -r=%t4.o,_ZTI4Base,pl \
+; RUN:   -r=%t4.o,_ZTI7Derived,pl \
+; RUN:   -r=%t4.o,_ZTV4Base,pl \
+; RUN:   -r=%t3.o,main,plx \
+; RUN:   -r=%t3.o,_Znwm, \
+; RUN:   -r=%t3.o,_ZN7DerivedC2Ev,pl \
+; RUN:   -r=%t3.o,_Z3fooP4Base, \
+; RUN:   -r=%t3.o,_ZN4BaseC2Ev,pl \
+; RUN:   -r=%t3.o,_ZN4BaseD2Ev, \
+; RUN:   -r=%t3.o,_ZN4BaseD0Ev, \
+; RUN:   -r=%t3.o,__cxa_pure_virtual, \
+; RUN:   -r=%t3.o,printf, \
+; RUN:   -r=%t3.o,_ZTV7Derived, \
+; RUN:   -r=%t3.o,_ZTV4Base, \
+; RUN:   -r=%t3.o,_ZTVN10__cxxabiv117__class_type_infoE, \
+; RUN:   -r=%t3.o,_ZTS4Base, \
+; RUN:   -r=%t3.o,_ZTI4Base, 2>&1 | FileCheck %s --check-prefix=THINREMARK
+
+; THINREMARK: Devirtualized call to {{.*}} (_ZN7DerivedD0Ev)
+; THINREMARK: single-impl: devirtualized a call to _ZN7DerivedD0Ev
+; THINREMARK: single-impl: devirtualized a call to _ZN7DerivedD0Ev
+
 ; ModuleID = 'tmp.cc'
 source_filename = "tmp.cc"
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
Index: llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll

[PATCH] D115648: [LTO] Ignore unreachable virtual functions in WPD in thin LTO

2021-12-14 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson accepted this revision.
tejohnson added a comment.
This revision is now accepted and ready to land.

lgtm with one more test simplification below.




Comment at: llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll:11
+; RUN: llvm-dis -o - %t-main.bc.0 | FileCheck %s --check-prefix=ENABLESPLITFLAG
+; ENABLESPLITFLAG-DAG: [[BaseD0:\^[0-9]+]] = gv: (name: "_ZN4BaseD0Ev", 
{{.*}}, funcFlags: ({{.*}} mustBeUnreachable: 1
+

Since we don't ever use variable BaseD0, there isn't a need to capture a value 
there. In fact, you can ignore it completely and then change all 4 llvm-dis 
instances in this test to check the same pattern like:

; FLAG: gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} 
mustBeUnreachable: 1

(and no need for the -DAG handling since there is only one pattern being 
checked per llvm-dis invocation).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115648/new/

https://reviews.llvm.org/D115648

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115648: [LTO] Ignore unreachable virtual functions in WPD in thin LTO

2021-12-14 Thread Mingming Liu via Phabricator via cfe-commits
luna added a comment.

thanks for review!




Comment at: llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll:64
+; Check that EnableSplitLTOUnit is off, and check the content of summary 
information.
+; RUN: llvm-dis -o - %t3.o | FileCheck %s --check-prefix=NOENABLESPLITFLAG
+; NOENABLESPLITFLAG-DAG: !{i32 1, !"EnableSplitLTOUnit", i32 0}

tejohnson wrote:
> This stuff is checked in other tests. Unless you are checking something 
> specific to this test, you can remove all of this. Actually, it would be good 
> to test here and in the earlier hybrid case that the summary for _ZN4BaseD0Ev 
> says it is unreachable. But that's probably all you need to test.
> 
> Ditto for %t4.o
Done by
1) checking the bit `mustBeUnreachable` for thin LTO and hybrid LTO, and remove 
irrelevant lines
2) Use one prefix per `FileCheck`.

I spent some time trying to figure out  why the regular LTO split modules 
(files with ".1" suffix in mod-extract output) don't have function summaries. 

Didn't figure out from code perspective (starting from 
`Index->enableSplitLTOUnit()` in 
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp#L3926),
 but it's probably intended in the sense that regular LTO module won't need 
index (which is generated for thin).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115648/new/

https://reviews.llvm.org/D115648

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115648: [LTO] Ignore unreachable virtual functions in WPD in thin LTO

2021-12-14 Thread Mingming Liu via Phabricator via cfe-commits
luna updated this revision to Diff 394429.
luna marked 2 inline comments as done.
luna added a comment.

Change test IR by removing irrelevant lines and using one prefix per FileCheck.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115648/new/

https://reviews.llvm.org/D115648

Files:
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/ThinLTO/X86/Inputs/devirt_after_filtering_unreachable_lib.ll
  llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll
  llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
  llvm/test/ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll

Index: llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
===
--- llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
+++ llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
@@ -1,9 +1,20 @@
-; Test that unreachable functions are ignored by WPD in hybrid LTO.
+; Test that unreachable functions are ignored by WPD in hybrid LTO, and thin LTO.
 ; In this test case, the unreachable function is the virtual deleting destructor of an abstract class.
 
 ; Generate split module with summary for hybrid Regular LTO WPD
 ; RUN: opt -thinlto-bc -thinlto-split-lto-unit %s -o %t-main.bc
-; RUN: opt -thinlto-bc -thinlto-split-lto-unit %p/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll -o %t-foo.bc
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit %p/Inputs/devirt_after_filtering_unreachable_lib.ll -o %t-foo.bc
+
+; Check that deleting destructor of pure virtual class is unreachable.
+; RUN: llvm-modextract -b -n=0 %t-main.bc -o %t-main.bc.0
+; RUN: llvm-dis -o - %t-main.bc.0 | FileCheck %s --check-prefix=ENABLESPLITFLAG
+; ENABLESPLITFLAG-DAG: [[BaseD0:\^[0-9]+]] = gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} mustBeUnreachable: 1
+
+; Check that deleting destructor of pure virtual class is unreachable.
+; RUN: llvm-modextract -b -n=0 %t-foo.bc -o %t-foo.bc.0
+; RUN: llvm-dis -o - %t-foo.bc.0 | FileCheck %s --check-prefix=LIBENABLESPLITFLAG
+; LIBENABLESPLITFLAG-DAG: [[BaseD0:\^[0-9]+]] = gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} mustBeUnreachable: 1
+
 ; Tests that devirtualization happens.
 ; RUN: llvm-lto2 run -save-temps %t-main.bc %t-foo.bc -pass-remarks=. -o %t \
 ; RUN:   -whole-program-visibility \
@@ -56,6 +67,59 @@
  
 ; REMARK-COUNT-1: single-impl: devirtualized a call to _ZN7DerivedD0Ev
 
+; Generate unsplit module with summary for ThinLTO index-based WPD.
+; RUN: opt -thinlto-bc -o %t3.o %s
+; RUN: opt -thinlto-bc -o %t4.o %p/Inputs/devirt_after_filtering_unreachable_lib.ll
+
+; Check that deleting destructor of pure virtual class is unreachable.
+; RUN: llvm-dis -o - %t3.o | FileCheck %s --check-prefix=NOENABLESPLITFLAG
+; NOENABLESPLITFLAG-DAG: [[BaseD0:\^[0-9]+]] = gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} mustBeUnreachable: 1
+
+; Check that deleting destructor of pure virtual class is unreachable.
+; RUN: llvm-dis -o - %t4.o | FileCheck %s --check-prefix=LIBNOENABLESPLITFLAG
+; LIBNOENABLESPLITFLAG-DAG: [[BaseD0:\^[0-9]+]] = gv: (name: "_ZN4BaseD0Ev", {{.*}}, funcFlags: ({{.*}} mustBeUnreachable: 1
+
+; Test that devirtualized happen in index based WPD
+; RUN: llvm-lto2 run %t4.o %t3.o -save-temps -pass-remarks=. \
+; RUN:   -whole-program-visibility \
+; RUN:   -wholeprogramdevirt-print-index-based \
+; RUN:   -o %t5 \
+; RUN:   -r=%t4.o,_ZN7Derived1xEv,pl \
+; RUN:   -r=%t4.o,printf, \
+; RUN:   -r=%t4.o,_Z3fooP4Base,pl \
+; RUN:   -r=%t4.o,_ZN7DerivedD2Ev,pl \
+; RUN:   -r=%t4.o,_ZN7DerivedD0Ev,pl \
+; RUN:   -r=%t4.o,_ZN4BaseD2Ev,pl \
+; RUN:   -r=%t4.o,_ZN4BaseD0Ev,pl \
+; RUN:   -r=%t4.o,__cxa_pure_virtual, \
+; RUN:   -r=%t4.o,_ZdlPv, \
+; RUN:   -r=%t4.o,_ZTV7Derived,pl \
+; RUN:   -r=%t4.o,_ZTVN10__cxxabiv120__si_class_type_infoE, \
+; RUN:   -r=%t4.o,_ZTS7Derived,pl \
+; RUN:   -r=%t4.o,_ZTVN10__cxxabiv117__class_type_infoE, \
+; RUN:   -r=%t4.o,_ZTS4Base,pl \
+; RUN:   -r=%t4.o,_ZTI4Base,pl \
+; RUN:   -r=%t4.o,_ZTI7Derived,pl \
+; RUN:   -r=%t4.o,_ZTV4Base,pl \
+; RUN:   -r=%t3.o,main,plx \
+; RUN:   -r=%t3.o,_Znwm, \
+; RUN:   -r=%t3.o,_ZN7DerivedC2Ev,pl \
+; RUN:   -r=%t3.o,_Z3fooP4Base, \
+; RUN:   -r=%t3.o,_ZN4BaseC2Ev,pl \
+; RUN:   -r=%t3.o,_ZN4BaseD2Ev, \
+; RUN:   -r=%t3.o,_ZN4BaseD0Ev, \
+; RUN:   -r=%t3.o,__cxa_pure_virtual, \
+; RUN:   -r=%t3.o,printf, \
+; RUN:   -r=%t3.o,_ZTV7Derived, \
+; RUN:   -r=%t3.o,_ZTV4Base, \
+; RUN:   -r=%t3.o,_ZTVN10__cxxabiv117__class_type_infoE, \
+; RUN:   -r=%t3.o,_ZTS4Base, \
+; RUN:   -r=%t3.o,_ZTI4Base, 2>&1 | FileCheck %s --check-prefix=THINREMARK
+
+; THINREMARK: Devirtualized call to {{.*}} (_ZN7DerivedD0Ev)
+; THINREMARK: single-impl: devirtualized a call to _ZN7DerivedD0Ev
+; THINREMARK: single-impl: devirtualized a call to _ZN7DerivedD0Ev
+
 ; ModuleID = 'tmp.cc'
 source_filename = "tmp.cc"
 target datalayout = 

[PATCH] D115648: [LTO] Ignore unreachable virtual functions in WPD in thin LTO

2021-12-14 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll:64
+; Check that EnableSplitLTOUnit is off, and check the content of summary 
information.
+; RUN: llvm-dis -o - %t3.o | FileCheck %s --check-prefix=NOENABLESPLITFLAG
+; NOENABLESPLITFLAG-DAG: !{i32 1, !"EnableSplitLTOUnit", i32 0}

This stuff is checked in other tests. Unless you are checking something 
specific to this test, you can remove all of this. Actually, it would be good 
to test here and in the earlier hybrid case that the summary for _ZN4BaseD0Ev 
says it is unreachable. But that's probably all you need to test.

Ditto for %t4.o



Comment at: llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll:127
+; RUN:   -r=%t3.o,_ZTS4Base, \
+; RUN:   -r=%t3.o,_ZTI4Base, 2>&1 | FileCheck %s --check-prefix=PRINT 
--check-prefix=THINREMARK
+

Unless you need to share only some of the check results with another 
invocation, just use a single check prefix.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115648/new/

https://reviews.llvm.org/D115648

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D115648: [LTO] Ignore unreachable virtual functions in WPD in thin LTO

2021-12-14 Thread Mingming Liu via Phabricator via cfe-commits
luna updated this revision to Diff 394389.
luna added a comment.

Rebase to main


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115648/new/

https://reviews.llvm.org/D115648

Files:
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/ThinLTO/X86/Inputs/devirt_after_filtering_unreachable_lib.ll
  llvm/test/ThinLTO/X86/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll
  llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
  llvm/test/ThinLTO/X86/devirt_hybrid_after_filtering_unreachable.ll

Index: llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
===
--- llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
+++ llvm/test/ThinLTO/X86/devirt_after_filtering_unreachable.ll
@@ -1,9 +1,9 @@
-; Test that unreachable functions are ignored by WPD in hybrid LTO.
+; Test that unreachable functions are ignored by WPD in hybrid LTO, and thin LTO.
 ; In this test case, the unreachable function is the virtual deleting destructor of an abstract class.
 
 ; Generate split module with summary for hybrid Regular LTO WPD
 ; RUN: opt -thinlto-bc -thinlto-split-lto-unit %s -o %t-main.bc
-; RUN: opt -thinlto-bc -thinlto-split-lto-unit %p/Inputs/devirt_hybrid_after_filtering_unreachable_lib.ll -o %t-foo.bc
+; RUN: opt -thinlto-bc -thinlto-split-lto-unit %p/Inputs/devirt_after_filtering_unreachable_lib.ll -o %t-foo.bc
 ; Tests that devirtualization happens.
 ; RUN: llvm-lto2 run -save-temps %t-main.bc %t-foo.bc -pass-remarks=. -o %t \
 ; RUN:   -whole-program-visibility \
@@ -56,6 +56,80 @@
  
 ; REMARK-COUNT-1: single-impl: devirtualized a call to _ZN7DerivedD0Ev
 
+; Generate unsplit module with summary for ThinLTO index-based WPD.
+; RUN: opt -thinlto-bc -o %t3.o %s
+; RUN: opt -thinlto-bc -o %t4.o %p/Inputs/devirt_after_filtering_unreachable_lib.ll
+
+; Check that EnableSplitLTOUnit is off, and check the content of summary information.
+; RUN: llvm-dis -o - %t3.o | FileCheck %s --check-prefix=NOENABLESPLITFLAG
+; NOENABLESPLITFLAG-DAG: !{i32 1, !"EnableSplitLTOUnit", i32 0}
+; NOENABLESPLITFLAG-DAG: [[BaseD0:\^[0-9]+]] = gv: (name: "_ZN4BaseD0Ev"
+; NOENABLESPLITFLAG-DAG: [[BaseD2:\^[0-9]+]] = gv: (name: "_ZN4BaseD2Ev"
+; NOENABLESPLITFLAG-DAG: [[BaseTI:\^[0-9]+]] = gv: (name: "_ZTI4Base"
+; NOENABLESPLITFLAG-DAG: [[PureVirtual:\^[0-9]+]] = gv: (name: "__cxa_pure_virtual"
+; NOENABLESPLITFLAG-DAG: [[Base:\^[0-9]+]] = gv: (name: "_ZTV4Base", {{.*}} vTableFuncs: ((virtFunc: [[BaseD2]], offset: 16), (virtFunc: [[BaseD0]], offset: 24)), refs: ([[BaseTI]], [[BaseD2]], [[BaseD0]], [[PureVirtual]])
+; NOENABLESPLITFLAG-DAG: typeidCompatibleVTable: (name: "_ZTS4Base", summary: ((offset: 16, [[Base]])))
+; NOENABLESPLITFLAG-DAG: typeidCompatibleVTable: (name: "_ZTSM4BaseFvvE.virtual", summary: ((offset: 32, [[Base]])))
+
+; Check that EnableSplitLTOUnit is off, and check the content of summary information.
+; RUN: llvm-dis -o - %t4.o | FileCheck %s --check-prefix=LIBNOENABLESPLITFLAG
+; LIBNOENABLESPLITFLAG-DAG: !{i32 1, !"EnableSplitLTOUnit", i32 0}
+; LIBNOENABLESPLITFLAG-DAG: [[DerivedD0:\^[0-9]+]] = gv: (name: "_ZN7DerivedD0Ev"
+; LIBNOENABLESPLITFLAG-DAG: [[BaseD0:\^[0-9]+]] = gv: (name: "_ZN4BaseD0Ev"
+; LIBNOENABLESPLITFLAG-DAG: [[DerivedTI:\^[0-9]+]] = gv: (name: "_ZTI7Derived"
+; LIBNOENABLESPLITFLAG-DAG: [[DerivedD2:\^[0-9]+]] = gv: (name: "_ZN7DerivedD2Ev"
+; LIBNOENABLESPLITFLAG-DAG: [[DerivedX:\^[0-9]+]] = gv: (name: "_ZN7Derived1xEv"
+; LIBNOENABLESPLITFLAG-DAG: [[BaseTI:\^[0-9]+]] = gv: (name: "_ZTI4Base"
+; LIBNOENABLESPLITFLAG-DAG: [[PureVirtual:\^[0-9]+]] = gv: (name: "__cxa_pure_virtual"
+; LIBNOENABLESPLITFLAG-DAG: [[BaseD2:\^[0-9]+]] = gv: (name: "_ZN4BaseD2Ev"
+; LIBNOENABLESPLITFLAG-DAG: [[Base:\^[0-9]+]] = gv: (name: "_ZTV4Base", {{.*}} vTableFuncs: ((virtFunc: [[BaseD2]], offset: 16), (virtFunc: [[BaseD0]], offset: 24)), refs: ([[BaseTI]], [[BaseD2]], [[BaseD0]], [[PureVirtual]])
+; LIBNOENABLESPLITFLAG-DAG: [[Derived:\^[0-9]+]] = gv: (name: "_ZTV7Derived", {{.*}} vTableFuncs: ((virtFunc: [[DerivedD2]], offset: 16), (virtFunc: [[DerivedD0]], offset: 24), (virtFunc: [[DerivedX]], offset: 32)), refs: ([[DerivedTI]], [[DerivedX]], [[DerivedD2]], [[DerivedD0]])
+; LIBNOENABLESPLITFLAG-DAG: typeidCompatibleVTable: (name: "_ZTS4Base", summary: ((offset: 16, [[Derived]]), (offset: 16, [[Base]])))
+; LIBNOENABLESPLITFLAG-DAG: typeidCompatibleVTable: (name: "_ZTS7Derived", summary: ((offset: 16, [[Derived]])))
+; LIBNOENABLESPLITFLAG-DAG: typeidCompatibleVTable: (name: "_ZTSM4BaseFvvE.virtual", summary: ((offset: 32, [[Derived]]), (offset: 32, [[Base]])))
+; LIBNOENABLESPLITFLAG-DAG: typeidCompatibleVTable: (name: "_ZTSM7DerivedFvvE.virtual", summary: ((offset: 32, [[Derived]])))
+
+; Index based WPD
+; RUN: llvm-lto2 run %t4.o %t3.o -save-temps -pass-remarks=. \
+; RUN:   -whole-program-visibility \
+; RUN:   -wholeprogramdevirt-print-index-based \
+; RUN:   -o %t5 \
+;