Skip to content

Commit 7c724a8

Browse files
committed
[AMDGPU] Do not check max-bb for a single block callee
-amdgpu-inline-max-bb option could lead to a suboptimal codegen preventing inlining of really simple functions including pure wrapper calls. Relax the cutoff by allowing to call a function with a single block on the grounds that it will not increase total number of blocks after inlining. Differential Revision: https://reviews.llvm.org/D97744
1 parent ea1a1eb commit 7c724a8

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,9 @@ bool GCNTTIImpl::areInlineCompatible(const Function *Caller,
11491149

11501150
// Hack to make compile times reasonable.
11511151
if (InlineMaxBB && !Callee->hasFnAttribute(Attribute::InlineHint)) {
1152-
// Single BB does not increase total BB amount, thus subtract 1.
1152+
// Single BB does not increase total BB amount.
1153+
if (Callee->size() == 1)
1154+
return true;
11531155
size_t BBSize = Caller->size() + Callee->size() - 1;
11541156
return BBSize <= InlineMaxBB;
11551157
}

llvm/test/CodeGen/AMDGPU/amdgpu-inline.ll

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
; RUN: opt -mtriple=amdgcn--amdhsa -data-layout=A5 -O3 -S -inline-threshold=1 < %s | FileCheck -check-prefix=GCN -check-prefix=GCN-INL1 %s
2-
; RUN: opt -mtriple=amdgcn--amdhsa -data-layout=A5 -O3 -S < %s | FileCheck -check-prefix=GCN -check-prefix=GCN-INLDEF %s
3-
; RUN: opt -mtriple=amdgcn--amdhsa -data-layout=A5 -passes='default<O3>' -S -inline-threshold=1 < %s | FileCheck -check-prefix=GCN -check-prefix=GCN-INL1 %s
4-
; RUN: opt -mtriple=amdgcn--amdhsa -data-layout=A5 -passes='default<O3>' -S < %s | FileCheck -check-prefix=GCN -check-prefix=GCN-INLDEF %s
1+
; RUN: opt -mtriple=amdgcn--amdhsa -data-layout=A5 -O3 -S -inline-threshold=1 < %s | FileCheck -check-prefixes=GCN,GCN-INL1,GCN-MAXBBDEF %s
2+
; RUN: opt -mtriple=amdgcn--amdhsa -data-layout=A5 -O3 -S < %s | FileCheck -check-prefixes=GCN,GCN-INLDEF,GCN-MAXBBDEF %s
3+
; RUN: opt -mtriple=amdgcn--amdhsa -data-layout=A5 -passes='default<O3>' -S -inline-threshold=1 < %s | FileCheck -check-prefixes=GCN,GCN-INL1,GCN-MAXBBDEF %s
4+
; RUN: opt -mtriple=amdgcn--amdhsa -data-layout=A5 -passes='default<O3>' -S < %s | FileCheck -check-prefixes=GCN,GCN-INLDEF,GCN-MAXBBDEF %s
5+
; RUN: opt -mtriple=amdgcn--amdhsa -data-layout=A5 -passes='default<O3>' -S -amdgpu-inline-max-bb=1 < %s | FileCheck -check-prefixes=GCN,GCN-MAXBB1 %s
56

67
define coldcc float @foo(float %x, float %y) {
78
entry:
@@ -57,12 +58,14 @@ entry:
5758
}
5859

5960
; GCN: define amdgpu_kernel void @test_inliner(
60-
; GCN-INL1: %c1 = tail call coldcc float @foo(
61-
; GCN-INLDEF: %cmp.i = fcmp ogt float %tmp2, 0.000000e+00
62-
; GCN: %div.i{{[0-9]*}} = fdiv float 1.000000e+00, %c
63-
; GCN: %div.i{{[0-9]*}} = fdiv float 2.000000e+00, %tmp1.i
64-
; GCN: call void @foo_noinline(
65-
; GCN: tail call float @_Z3sinf(
61+
; GCN-INL1: %c1 = tail call coldcc float @foo(
62+
; GCN-INLDEF: %cmp.i = fcmp ogt float %tmp2, 0.000000e+00
63+
; GCN-MAXBBDEF: %div.i{{[0-9]*}} = fdiv float 1.000000e+00, %c
64+
; GCN-MAXBBDEF: %div.i{{[0-9]*}} = fdiv float 2.000000e+00, %tmp1.i
65+
; GCN-MAXBB1: call coldcc void @foo_private_ptr
66+
; GCN-MAXBB1: call coldcc void @foo_private_ptr2
67+
; GCN: call void @foo_noinline(
68+
; GCN: tail call float @_Z3sinf(
6669
define amdgpu_kernel void @test_inliner(float addrspace(1)* nocapture %a, i32 %n) {
6770
entry:
6871
%pvt_arr = alloca [64 x float], align 4, addrspace(5)
@@ -95,7 +98,8 @@ entry:
9598
}
9699

97100
; GCN: define amdgpu_kernel void @test_inliner_multi_pvt_ptr(
98-
; GCN: %div.i{{[0-9]*}} = fdiv float 2.000000e+00, %tmp1.i
101+
; GCN-MAXBBDEF: %div.i{{[0-9]*}} = fdiv float 2.000000e+00, %tmp1.i
102+
; GCN-MAXBB1: call coldcc void @foo_private_ptr2
99103
define amdgpu_kernel void @test_inliner_multi_pvt_ptr(float addrspace(1)* nocapture %a, i32 %n, float %v) {
100104
entry:
101105
%pvt_arr1 = alloca [32 x float], align 4, addrspace(5)
@@ -147,6 +151,24 @@ entry:
147151
ret void
148152
}
149153

154+
; GCN: define amdgpu_kernel void @test_inliner_maxbb_singlebb(
155+
; GCN: tail call float @_Z3sinf
156+
define amdgpu_kernel void @test_inliner_maxbb_singlebb(float addrspace(1)* nocapture %a, i32 %n) {
157+
entry:
158+
%cmp = icmp eq i32 %n, 1
159+
br i1 %cmp, label %bb.1, label %bb.2
160+
br label %bb.1
161+
162+
bb.1:
163+
store float 1.0, float* undef
164+
br label %bb.2
165+
166+
bb.2:
167+
%c = call float @sin_wrapper(float 1.0)
168+
store float %c, float addrspace(1)* %a
169+
ret void
170+
}
171+
150172
declare i32 @llvm.amdgcn.workitem.id.x() #1
151173
declare float @_Z3sinf(float) #1
152174

0 commit comments

Comments
 (0)