[PATCH] D39581: [PartialInliner] Skip call sites where inlining fails.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 2 17:03:30 PDT 2017


fhahn created this revision.
Herald added a subscriber: eraman.

InlineFunction can fail, for example when trying to inline vararg
fuctions. In those cases, we do not want to bump partial inlining
counters or set AnyInlined to true, because this could leave an unused
function hanging around.


https://reviews.llvm.org/D39581

Files:
  lib/Transforms/IPO/PartialInlining.cpp
  test/Transforms/CodeExtractor/PartialInlineNoInline.ll


Index: test/Transforms/CodeExtractor/PartialInlineNoInline.ll
===================================================================
--- /dev/null
+++ test/Transforms/CodeExtractor/PartialInlineNoInline.ll
@@ -0,0 +1,40 @@
+; RUN: opt < %s -partial-inliner -S -stats 2>&1 | FileCheck %s
+; RUN: opt < %s -passes=partial-inliner -S  -stats 2>&1 | FileCheck %s
+
+ at stat = external global i32, align 4
+
+define i32 @inline_fail(i32 %count, ...) {
+entry:
+  %vargs = alloca i8*, align 8
+  %vargs1 = bitcast i8** %vargs to i8*
+  call void @llvm.va_start(i8* %vargs1)
+  %stat1 = load i32, i32* @stat, align 4
+  %cmp = icmp slt i32 %stat1, 0
+  br i1 %cmp, label %bb2, label %bb1
+
+bb1:                                              ; preds = %entry
+  %vg1 = add nsw i32 %stat1, 1
+  store i32 %vg1, i32* @stat, align 4
+  %va1 = va_arg i8** %vargs, i32
+  call void @foo(i32 %count, i32 %va1) #2
+  br label %bb2
+
+bb2:                                              ; preds = %bb1, %entry
+  %res = phi i32 [ 1, %bb1 ], [ 0, %entry ]
+  call void @llvm.va_end(i8* %vargs1)
+  ret i32 %res
+}
+
+define i32 @caller(i32 %arg) {
+bb:
+  %res = tail call i32 (i32, ...) @inline_fail(i32 %arg, i32 %arg)
+  ret i32 %res
+}
+
+declare void @foo(i32, i32)
+declare void @llvm.va_start(i8*)
+declare void @llvm.va_end(i8*)
+
+; CHECK: tail call i32 (i32, ...) @inline_fail(i32 %arg, i32 %arg)
+; CHECK-NOT: inline_fail.1_bb1
+; CHECK-NOT: partial-inlining
Index: lib/Transforms/IPO/PartialInlining.cpp
===================================================================
--- lib/Transforms/IPO/PartialInlining.cpp
+++ lib/Transforms/IPO/PartialInlining.cpp
@@ -939,7 +939,8 @@
     });
 
     InlineFunctionInfo IFI(nullptr, GetAssumptionCache, PSI);
-    InlineFunction(CS, IFI);
+    if (!InlineFunction(CS, IFI))
+      continue;
 
     // Now update the entry count:
     if (CalleeEntryCountV && CallSiteToProfCountMap.count(User)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39581.121412.patch
Type: text/x-patch
Size: 1928 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171103/a0291893/attachment.bin>


More information about the llvm-commits mailing list