Skip to content

Commit be663a4

Browse files
committed
Revert "Do not inline self-recursive functions into other functions."
This reverts commit dc65f70 since it looks like the updated test is broken on some configurations. I'll investigate, fix, and reapply soon.
1 parent f25b887 commit be663a4

File tree

2 files changed

+6
-30
lines changed

2 files changed

+6
-30
lines changed

lib/SILPasses/IPO/PerformanceInliner.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -542,16 +542,6 @@ bool SILPerformanceInliner::hasInliningCycle(SILFunction *Caller,
542542
return InlinedBefore;
543543
}
544544

545-
546-
static bool calleeIsSelfRecursive(SILFunction *Callee) {
547-
for (auto &BB : *Callee)
548-
for (auto &I : BB)
549-
if (auto Apply = FullApplySite::isa(&I))
550-
if (Apply.getCalleeFunction() == Callee)
551-
return true;
552-
return false;
553-
}
554-
555545
// Returns the callee of an apply_inst if it is basically inlinable.
556546
SILFunction *SILPerformanceInliner::getEligibleFunction(FullApplySite AI) {
557547

@@ -634,16 +624,6 @@ SILFunction *SILPerformanceInliner::getEligibleFunction(FullApplySite AI) {
634624
Callee->getName() << ".\n");
635625
return nullptr;
636626
}
637-
638-
// Inlining self-recursive functions into other functions can result
639-
// in excessive code duplication since we run the inliner multiple
640-
// times in our pipeline.
641-
if (calleeIsSelfRecursive(Callee)) {
642-
DEBUG(llvm::dbgs() << " FAIL: Callee is self-recursive in " <<
643-
Callee->getName() << ".\n");
644-
return nullptr;
645-
}
646-
647627
DEBUG(llvm::dbgs() << " Eligible callee: " <<
648628
Callee->getName() << "\n");
649629

test/SILPasses/inline_recursive.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,13 @@ private func recFunc(x: Int) -> Int {
77
return 0
88
}
99

10-
// Ensure that we do not inline self-recursive functions into other
11-
// functions since doing so can result in large code growth if we run
12-
// the inlining pass multiple times.
13-
14-
// CHECK-LABEL: sil hidden @_TF16inline_recursive6callitFT_Si
10+
//CHECK-LABEL: sil {{.*}}callit
1511
// CHECK: bb0:
16-
// CHECK: [[FN:%.*]] = function_ref @_TF16inline_recursiveP33_38E63D320CFF538A1F98BBC31453B1EB7recFuncFSiSi
17-
// CHECK: [[BUILTIN_INT:%.*]] = integer_literal $Builtin.Int64, 3
18-
// CHECK: [[INT:%.*]] = struct $Int ([[BUILTIN_INT]] : $Builtin.Int64)
19-
// CHECK: [[APPLY:%.*]] = apply [[FN]]([[INT]])
20-
// CHECK: return [[APPLY]]
12+
// CHECK-NEXT: integer_literal {{.*}}, 0
13+
// CHECK-NEXT: struct
14+
// CHECK-NEXT: return
15+
2116
func callit() -> Int {
2217
return recFunc(3)
2318
}
19+

0 commit comments

Comments
 (0)