[PATCH] D120006: [GlobalDCE] [VFE] Avoid dropping vfunc dependencies when an invalid vtable entry is present

Kuba (Brecka) Mracek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 16 21:24:53 PST 2022


kubamracek created this revision.
kubamracek added reviewers: fhahn, ostannard, pcc.
kubamracek added a project: LLVM.
Herald added subscribers: ormris, hiraditya.
kubamracek requested review of this revision.

See the attached (pre-committed) test case. Looks like when we scan vtables for a particular vload in ScanVTableLoad and an entry in one possible vtable is invalid (null or non-fptr), we bail in a wrong way -- we completely stop the scanning of vtables with a `return` and this results in dropped dependencies because we don't perform `GVDependencies[Caller].insert(Callee);` on following valid vtable entries. Let's fix that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120006

Files:
  llvm/lib/Transforms/IPO/GlobalDCE.cpp
  llvm/test/Transforms/GlobalDCE/virtual-functions-null.ll


Index: llvm/test/Transforms/GlobalDCE/virtual-functions-null.ll
===================================================================
--- llvm/test/Transforms/GlobalDCE/virtual-functions-null.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-null.ll
@@ -20,7 +20,7 @@
 ]}, align 8, !type !{i64 0, !"vfunc1.type"}, !type !{i64 8, !"vfunc2.type"}, !vcall_visibility !{i64 2}
 
 ; CHECK:      @vtableB = internal unnamed_addr constant { [2 x i8*] } { [2 x i8*] [
-; CHECK-SAME:   i8* null,
+; CHECK-SAME:   i8* bitcast (void ()* @vfunc1 to i8*),
 ; CHECK-SAME:   i8* bitcast (void ()* @vfunc2 to i8*)
 ; CHECK-SAME: ] }, align 8
 
Index: llvm/lib/Transforms/IPO/GlobalDCE.cpp
===================================================================
--- llvm/lib/Transforms/IPO/GlobalDCE.cpp
+++ llvm/lib/Transforms/IPO/GlobalDCE.cpp
@@ -214,14 +214,14 @@
     if (!Ptr) {
       LLVM_DEBUG(dbgs() << "can't find pointer in vtable!\n");
       VFESafeVTables.erase(VTable);
-      return;
+      continue;
     }
 
     auto Callee = dyn_cast<Function>(Ptr->stripPointerCasts());
     if (!Callee) {
       LLVM_DEBUG(dbgs() << "vtable entry is not function pointer!\n");
       VFESafeVTables.erase(VTable);
-      return;
+      continue;
     }
 
     LLVM_DEBUG(dbgs() << "vfunc dep " << Caller->getName() << " -> "


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120006.409483.patch
Type: text/x-patch
Size: 1315 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220217/a8adb1f3/attachment.bin>


More information about the llvm-commits mailing list