[llvm] 1c5d547 - Revert "Reapply "[llvm] Teach GlobalDCE about dso_local_equivalent""

Leonard Chan via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 15 11:11:51 PDT 2024


Author: Leonard Chan
Date: 2024-04-15T11:11:20-07:00
New Revision: 1c5d5478f7f35d7f212fcbf2af042fc3c720e9ed

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

LOG: Revert "Reapply "[llvm] Teach GlobalDCE about dso_local_equivalent""

This reverts commit b8b2f9902cb23af0811ec218a4f43226c0691510.

This was failing on a local build.

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/TypeMetadataUtils.h
    llvm/test/Transforms/GlobalDCE/virtual-functions-relative-pointers-bad.ll
    llvm/test/Transforms/GlobalDCE/virtual-functions-relative-pointers-gep.ll
    llvm/test/Transforms/GlobalDCE/virtual-functions-relative-pointers.ll

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/TypeMetadataUtils.h b/llvm/include/llvm/Analysis/TypeMetadataUtils.h
index bdb477b54b532d..2c7ce0858b9d3e 100644
--- a/llvm/include/llvm/Analysis/TypeMetadataUtils.h
+++ b/llvm/include/llvm/Analysis/TypeMetadataUtils.h
@@ -87,8 +87,8 @@ std::pair<Function *, Constant *>
 getFunctionAtVTableOffset(GlobalVariable *GV, uint64_t Offset, Module &M);
 
 /// Finds the same "relative pointer" pattern as described above, where the
-/// target is `C`, and replaces the entire pattern with a constant zero.
-void replaceRelativePointerUsersWithZero(Constant *C);
+/// target is `F`, and replaces the entire pattern with a constant zero.
+void replaceRelativePointerUsersWithZero(Function *F);
 
 } // namespace llvm
 

diff  --git a/llvm/test/Transforms/GlobalDCE/virtual-functions-relative-pointers-bad.ll b/llvm/test/Transforms/GlobalDCE/virtual-functions-relative-pointers-bad.ll
index 9a4bff80383cb7..9d87fdb084a126 100644
--- a/llvm/test/Transforms/GlobalDCE/virtual-functions-relative-pointers-bad.ll
+++ b/llvm/test/Transforms/GlobalDCE/virtual-functions-relative-pointers-bad.ll
@@ -16,32 +16,14 @@ declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata)
 
 ; CHECK:      @vtable = internal unnamed_addr constant { [3 x i32] } zeroinitializer, align 8, !type !0, !type !1, !vcall_visibility !2
 
- at vtable2 = internal unnamed_addr constant { [3 x i32] } { [3 x i32] [
-  i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @vfunc3 to i64), i64 ptrtoint (ptr @vtable2 to i64)) to i32),
-  i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @vfunc4 to i64), i64 ptrtoint (ptr @vtable2 to i64)) to i32),
-
-  ; a "bad" relative pointer because it's base is not the @vtable symbol
-  i32 trunc (i64 sub (i64 ptrtoint (ptr @weird_ref_3         to i64), i64 ptrtoint (ptr @weird_ref_4 to i64)) to i32)
-]}, align 4, !type !3, !type !4, !vcall_visibility !{i64 2}
-!3 = !{i64 0, !"vfunc3.type"}
-!4 = !{i64 4, !"vfunc4.type"}
-
-; CHECK:      @vtable2 = internal unnamed_addr constant { [3 x i32] } zeroinitializer, align 4, !type !3, !type !4, !vcall_visibility !2
-
 define internal void @vfunc1() { ret void }
 define internal void @vfunc2() { ret void }
 define internal void @weird_ref_1() { ret void }
 define internal void @weird_ref_2() { ret void }
-declare void @vfunc3()
-declare void @vfunc4()
-declare void @weird_ref_3()
-declare void @weird_ref_4()
 
 define void @main() {
   %1 = ptrtoint ptr @vtable to i64 ; to keep @vtable alive
   call void @weird_ref_2()
-  %2 = ptrtoint ptr @vtable2 to i64 ; to keep @vtable2 alive
-  call void @weird_ref_4()
   ret void
 }
 

diff  --git a/llvm/test/Transforms/GlobalDCE/virtual-functions-relative-pointers-gep.ll b/llvm/test/Transforms/GlobalDCE/virtual-functions-relative-pointers-gep.ll
index d89b024e7a6d02..fb45d37dde6e4c 100644
--- a/llvm/test/Transforms/GlobalDCE/virtual-functions-relative-pointers-gep.ll
+++ b/llvm/test/Transforms/GlobalDCE/virtual-functions-relative-pointers-gep.ll
@@ -19,20 +19,6 @@ declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata)
 ; CHECK-SAME:   i32 0
 ; CHECK-SAME: ] }, align 8, !type !0, !type !1, !vcall_visibility !2
 
- at vtable2 = internal unnamed_addr constant { [4 x i32] } { [4 x i32] [
-  i32 42,
-  i32 1337,
-  i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @vfunc3_live_extern to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [4 x i32] }, ptr @vtable2, i32 0, i32 0, i32 2) to i64)) to i32),
-  i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @vfunc4_dead_extern to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [4 x i32] }, ptr @vtable2, i32 0, i32 0, i32 2) to i64)) to i32)
-]}, align 4, !type !3, !type !4, !vcall_visibility !{i64 2}
-!3 = !{i64 8, !"vfunc3.type"}
-!4 = !{i64 12, !"vfunc4.type"}
-
-; CHECK:      @vtable2 = internal unnamed_addr constant { [4 x i32] } { [4 x i32] [
-; CHECK-SAME:   i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @vfunc3_live_extern to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [4 x i32] }, ptr @vtable2, i32 0, i32 0, i32 2) to i64)) to i32),
-; CHECK-SAME:   i32 0
-; CHECK-SAME: ] }, align 4, !type !3, !type !4, !vcall_visibility !2
-
 ; (1) vfunc1_live is referenced from @main, stays alive
 define internal void @vfunc1_live() {
   ; CHECK: define internal void @vfunc1_live(
@@ -45,19 +31,9 @@ define internal void @vfunc2_dead() {
   ret void
 }
 
-; (3) vfunc3_live_extern is referenced from @main, stays alive
-; CHECK: declare void @vfunc3_live_extern
-declare void @vfunc3_live_extern()
-
-; (4) vfunc4_dead_extern is never referenced, gets removed and vtable slot is null'd
-; CHECK-NOT: declare void @vfunc4_dead_extern
-declare void @vfunc4_dead_extern()
-
 define void @main() {
   %1 = ptrtoint ptr @vtable to i64 ; to keep @vtable alive
   %2 = tail call { ptr, i1 } @llvm.type.checked.load(ptr null, i32 0, metadata !"vfunc1.type")
-  %3 = ptrtoint ptr @vtable2 to i64 ; to keep @vtable2 alive
-  %4 = tail call { ptr, i1 } @llvm.type.checked.load(ptr null, i32 0, metadata !"vfunc3.type")
   ret void
 }
 

diff  --git a/llvm/test/Transforms/GlobalDCE/virtual-functions-relative-pointers.ll b/llvm/test/Transforms/GlobalDCE/virtual-functions-relative-pointers.ll
index b652765296bc57..76a617ea99e6fc 100644
--- a/llvm/test/Transforms/GlobalDCE/virtual-functions-relative-pointers.ll
+++ b/llvm/test/Transforms/GlobalDCE/virtual-functions-relative-pointers.ll
@@ -17,20 +17,6 @@ declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata)
 ; CHECK-SAME:   i32 0
 ; CHECK-SAME: ] }, align 8, !type !0, !type !1, !vcall_visibility !2
 
-; Similar to above, but the vtable is more aligned to how C++ relative vtables look.
-; That is, the functions may not be dso-local.
- at vtable2 = internal unnamed_addr constant { [2 x i32] } { [2 x i32] [
-  i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @vfunc3_live_extern to i64), i64 ptrtoint (ptr @vtable2 to i64)) to i32),
-  i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @vfunc4_dead_extern to i64), i64 ptrtoint (ptr @vtable2 to i64)) to i32)
-]}, align 4, !type !3, !type !4, !vcall_visibility !{i64 2}
-!3 = !{i64 0, !"vfunc3.type"}
-!4 = !{i64 4, !"vfunc4.type"}
-
-; CHECK:      @vtable2 = internal unnamed_addr constant { [2 x i32] } { [2 x i32] [
-; CHECK-SAME:   i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @vfunc3_live_extern to i64), i64 ptrtoint (ptr @vtable2 to i64)) to i32),
-; CHECK-SAME:   i32 0
-; CHECK-SAME: ] }, align 4, !type !3, !type !4, !vcall_visibility !2
-
 ; (1) vfunc1_live is referenced from @main, stays alive
 define internal void @vfunc1_live() {
   ; CHECK: define internal void @vfunc1_live(
@@ -43,19 +29,9 @@ define internal void @vfunc2_dead() {
   ret void
 }
 
-; (3) vfunc3_live_extern is referenced from @main, stays alive
-; CHECK: declare void @vfunc3_live_extern
-declare void @vfunc3_live_extern()
-
-; (4) vfunc4_dead_extern is never referenced, gets removed and vtable slot is null'd
-; CHECK-NOT: declare void @vfunc4_dead_extern
-declare void @vfunc4_dead_extern()
-
 define void @main() {
   %1 = ptrtoint ptr @vtable to i64 ; to keep @vtable alive
   %2 = tail call { ptr, i1 } @llvm.type.checked.load(ptr null, i32 0, metadata !"vfunc1.type")
-  %3 = ptrtoint ptr @vtable2 to i64 ; to keep @vtable2 alive
-  %4 = tail call { ptr, i1 } @llvm.type.checked.load(ptr null, i32 0, metadata !"vfunc3.type")
   ret void
 }
 


        


More information about the llvm-commits mailing list