[PATCH] D136383: [PartialInlining] Enable recursive partial inlining.

Mark Lacey via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 20 14:44:09 PDT 2022


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

It seems unnecessarily limiting to disallow recursive partial
inlining, and there are clearly cases where it can benefit
code by avoiding a function call and potentially enabling
other transformations like dead argument elimination
in cases where an argument is only used prior to the early-out
test at the top of the function.

The pass already properly rewrites the recursive calls
within the body of the freshly cloned function, so the only
change here is removing the bail-out when recursion is
detected.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136383

Files:
  llvm/lib/Transforms/IPO/PartialInlining.cpp
  llvm/test/Transforms/PartialInlining/recursive_partial_inlining.ll


Index: llvm/test/Transforms/PartialInlining/recursive_partial_inlining.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/PartialInlining/recursive_partial_inlining.ll
@@ -0,0 +1,29 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -partial-inliner -skip-partial-inlining-cost-analysis --simplifycfg -S < %s | FileCheck %s
+define void @_Z26recursive_partial_inliningi(i32 noundef %i) local_unnamed_addr {
+; CHECK-LABEL: @_Z26recursive_partial_inliningi(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i32 [[I:%.*]], 0
+; CHECK-NEXT:    br i1 [[CMP]], label [[COMMON_RET2:%.*]], label [[IF_END:%.*]]
+; CHECK:       common.ret2:
+; CHECK-NEXT:    ret void
+; CHECK:       if.end:
+; CHECK-NEXT:    [[SUB:%.*]] = add nsw i32 [[I]], -1
+; CHECK-NEXT:    [[CMP_I:%.*]] = icmp slt i32 [[SUB]], 0
+; CHECK-NEXT:    br i1 [[CMP_I]], label [[COMMON_RET2]], label [[CODEREPL_I:%.*]]
+; CHECK:       codeRepl.i:
+; CHECK-NEXT:    call void @_Z26recursive_partial_inliningi.1.if.end(i32 [[SUB]])
+; CHECK-NEXT:    br label [[COMMON_RET2]]
+;
+entry:
+  %cmp = icmp slt i32 %i, 0
+  br i1 %cmp, label %common.ret2, label %if.end
+
+common.ret2:                                      ; preds = %entry, %if.end
+  ret void
+
+if.end:                                           ; preds = %entry
+  %sub = add nsw i32 %i, -1
+  tail call void @_Z26recursive_partial_inliningi(i32 noundef %sub)
+  br label %common.ret2
+}
Index: llvm/lib/Transforms/IPO/PartialInlining.cpp
===================================================================
--- llvm/lib/Transforms/IPO/PartialInlining.cpp
+++ llvm/lib/Transforms/IPO/PartialInlining.cpp
@@ -1490,16 +1490,6 @@
     if (CurrFunc->use_empty())
       continue;
 
-    bool Recursive = false;
-    for (User *U : CurrFunc->users())
-      if (Instruction *I = dyn_cast<Instruction>(U))
-        if (I->getParent()->getParent() == CurrFunc) {
-          Recursive = true;
-          break;
-        }
-    if (Recursive)
-      continue;
-
     std::pair<bool, Function *> Result = unswitchFunction(*CurrFunc);
     if (Result.second)
       Worklist.push_back(Result.second);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136383.469364.patch
Type: text/x-patch
Size: 2223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221020/8a079d79/attachment-0001.bin>


More information about the llvm-commits mailing list