[PATCH] D115545: [Inline] Attempt to delete any discardable if unused functions

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 10 11:40:20 PST 2021


aeubanks created this revision.
Herald added subscribers: ormris, zzheng, hiraditya, eraman.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Previously we limited ourselves to only internal/private functions. We
can also delete linkonce_odr functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115545

Files:
  llvm/lib/Transforms/IPO/Inliner.cpp
  llvm/test/Transforms/Inline/delete-unused-function.ll
  llvm/test/Transforms/LoopUnroll/2011-08-09-PhiUpdate.ll


Index: llvm/test/Transforms/LoopUnroll/2011-08-09-PhiUpdate.ll
===================================================================
--- llvm/test/Transforms/LoopUnroll/2011-08-09-PhiUpdate.ll
+++ llvm/test/Transforms/LoopUnroll/2011-08-09-PhiUpdate.ll
@@ -107,17 +107,6 @@
 
 define linkonce_odr i32 @bar() nounwind uwtable ssp align 2 {
 ;
-; CHECK-LABEL: @bar(
-; CHECK-NEXT:  land.lhs.true:
-; CHECK-NEXT:    [[CMP4:%.*]] = call zeroext i1 @check()
-; CHECK-NEXT:    br i1 [[CMP4]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]]
-; CHECK:       cond.true:
-; CHECK-NEXT:    [[TMP7:%.*]] = call i32 @getval()
-; CHECK-NEXT:    br label [[COND_END]]
-; CHECK:       cond.end:
-; CHECK-NEXT:    [[COND:%.*]] = phi i32 [ [[TMP7]], [[COND_TRUE]] ], [ 0, [[LAND_LHS_TRUE:%.*]] ]
-; CHECK-NEXT:    ret i32 [[COND]]
-;
 entry:
   br i1 undef, label %land.lhs.true, label %cond.end
 
Index: llvm/test/Transforms/Inline/delete-unused-function.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Inline/delete-unused-function.ll
@@ -0,0 +1,32 @@
+; RUN: opt -passes=inline < %s -S | FileCheck %s
+
+; CHECK: define {{.*}}@caller
+; CHECK: define {{.*}}@f1
+; CHECK-NOT: define {{.*}}@f2
+; CHECK-NOT: define {{.*}}@f3
+; CHECK-NOT: define {{.*}}@f4
+
+define void @caller() {
+  call void @f1()
+  call void @f2()
+  call void @f3()
+  call void @f4()
+  ret void
+}
+
+define void @f1() {
+  ret void
+}
+
+define internal void @f2() {
+  ret void
+}
+
+define private void @f3() {
+  ret void
+}
+
+define linkonce_odr void @f4() {
+  ret void
+}
+
Index: llvm/lib/Transforms/IPO/Inliner.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Inliner.cpp
+++ llvm/lib/Transforms/IPO/Inliner.cpp
@@ -940,7 +940,7 @@
       // which may reduce the number of callers of other functions to one,
       // changing inline cost thresholds.
       bool CalleeWasDeleted = false;
-      if (Callee.hasLocalLinkage()) {
+      if (Callee.isDiscardableIfUnused()) {
         // To check this we also need to nuke any dead constant uses (perhaps
         // made dead by this operation on other functions).
         Callee.removeDeadConstantUsers();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115545.393555.patch
Type: text/x-patch
Size: 2237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211210/fac47d7e/attachment.bin>


More information about the llvm-commits mailing list