Skip to content

Commit ceec438

Browse files
[AlwaysInliner] Enable call site inlining to make flatten attribute working again (#53360)
Problem: Migration to new PM broke flatten attribute. This is one use case why LLVM should support inlining call-site with alwaysinline. The flatten attribute is nowdays broken, so we should either land patch like this one or remove everything related to flatten attribute from Clang. Second use case is something like "per call site inlining intrinsics" to control inlining even more; mentioned in https://lists.llvm.org/pipermail/cfe-dev/2018-September/059232.html Fixes llvm/llvm-project#53360 Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D117965
1 parent 3efa016 commit ceec438

File tree

5 files changed

+11
-33
lines changed

5 files changed

+11
-33
lines changed

clang/test/CodeGen/flatten.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
// UNSUPPORTED: experimental-new-pass-manager
2-
// Currently, different code seems to be intentionally generated under the new
3-
// PM since we alwaysinline functions and not callsites under new PM.
4-
// Under new PM, f() will not be inlined from g() since f is not marked as
5-
// alwaysinline.
6-
71
// RUN: %clang_cc1 -triple=x86_64-linux-gnu %s -emit-llvm -o - | FileCheck %s
82

93
void f(void) {}

clang/test/CodeGenCXX/flatten.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// UNSUPPORTED: experimental-new-pass-manager
2-
// See the comment for CodeGen/flatten.c on why this is unsupported with the new
3-
// PM.
4-
51
// RUN: %clang_cc1 -triple=x86_64-linux-gnu -std=c++11 %s -emit-llvm -o - | FileCheck %s
62

73
void f(void) {}

llvm/lib/Transforms/IPO/AlwaysInliner.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
5454
if (F.isPresplitCoroutine())
5555
continue;
5656

57-
if (!F.isDeclaration() && F.hasFnAttribute(Attribute::AlwaysInline) &&
58-
isInlineViable(F).isSuccess()) {
57+
if (!F.isDeclaration() && isInlineViable(F).isSuccess()) {
5958
Calls.clear();
6059

6160
for (User *U : F.users())
6261
if (auto *CB = dyn_cast<CallBase>(U))
63-
if (CB->getCalledFunction() == &F)
62+
if (CB->getCalledFunction() == &F &&
63+
CB->hasFnAttr(Attribute::AlwaysInline))
6464
Calls.insert(CB);
6565

6666
for (CallBase *CB : Calls) {

llvm/test/Transforms/Coroutines/coro-retcon-once-private.ll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
44
target triple = "x86_64-apple-macosx10.12.0"
55

6-
; CHECK: define internal { i8*, i32 } @f(i8* %buffer, i32* %array)
7-
; CHECK-NEXT: entry:
8-
; CHECK-NEXT: unreachable
6+
; CHECK-NOT: define {{.*}} @f(i8* %buffer, i32* %array)
97

108
define internal {i8*, i32} @f(i8* %buffer, i32* %array) {
119
entry:

llvm/test/Transforms/Inline/always-inline.ll

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
; RUN: opt < %s -inline-threshold=0 -always-inline -enable-new-pm=0 -S | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL
1+
; RUN: opt < %s -inline-threshold=0 -always-inline -enable-new-pm=0 -S | FileCheck %s --check-prefix=CHECK
22
;
33
; Ensure the threshold has no impact on these decisions.
4-
; RUN: opt < %s -inline-threshold=20000000 -always-inline -enable-new-pm=0 -S | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL
5-
; RUN: opt < %s -inline-threshold=-20000000 -always-inline -enable-new-pm=0 -S | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CALL
4+
; RUN: opt < %s -inline-threshold=20000000 -always-inline -enable-new-pm=0 -S | FileCheck %s --check-prefix=CHECK
5+
; RUN: opt < %s -inline-threshold=-20000000 -always-inline -enable-new-pm=0 -S | FileCheck %s --check-prefix=CHECK
66
;
77
; The new pass manager doesn't re-use any threshold based infrastructure for
8-
; the always inliner, but test that we get the correct result. The new PM
9-
; always inliner also doesn't support inlining call-site alwaysinline
10-
; annotations. It isn't clear that this is a reasonable use case for
11-
; 'alwaysinline'.
8+
; the always inliner, but test that we get the correct result.
129
; RUN: opt < %s -inline-threshold=0 -passes=always-inline -S | FileCheck %s --check-prefix=CHECK
1310
; RUN: opt < %s -inline-threshold=20000000 -passes=always-inline -S | FileCheck %s --check-prefix=CHECK
1411
; RUN: opt < %s -inline-threshold=-20000000 -passes=always-inline -S | FileCheck %s --check-prefix=CHECK
@@ -26,12 +23,6 @@ define i32 @outer1() {
2623
ret i32 %r
2724
}
2825

29-
; The always inliner can't DCE arbitrary internal functions. PR2945
30-
define internal i32 @pr2945() nounwind {
31-
; CHECK-LABEL: @pr2945(
32-
ret i32 0
33-
}
34-
3526
define internal void @inner2(i32 %N) alwaysinline {
3627
; CHECK-NOT: @inner2(
3728
%P = alloca i32, i32 %N
@@ -146,10 +137,9 @@ define i32 @inner7() {
146137
ret i32 1
147138
}
148139
define i32 @outer7() {
149-
; CHECK-CALL-LABEL: @outer7(
150-
; CHECK-CALL-NOT: call
151-
; CHECK-CALL: ret
152-
140+
; CHECK-LABEL: @outer7(
141+
; CHECK-NOT: call
142+
; CHECK: ret
153143
%r = call i32 @inner7() alwaysinline
154144
ret i32 %r
155145
}

0 commit comments

Comments
 (0)