llvm.org GIT mirror llvm / 8fac8d9
[AMDGPU] Improve code size cost model Summary: Added estimation for zero size insertelement, extractelement and llvm.fabs operators. Updated inline/unroll parameters default values. Reviewers: rampitec, arsenm Reviewed By: arsenm Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68881 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375109 91177308-0d34-0410-b5e6-96231b3b80d8 Daniil Fukalov 1 year, 4 days ago
6 changed file(s) with 61 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
5050
5151 // Inliner constraint to achieve reasonable compilation time
5252 static cl::opt
53 MaxBB("amdgpu-inline-max-bb", cl::Hidden, cl::init(300),
53 MaxBB("amdgpu-inline-max-bb", cl::Hidden, cl::init(1100),
5454 cl::desc("Maximum BB number allowed in a function after inlining"
5555 " (compile time constraint)"));
5656
5656 static cl::opt UnrollThresholdPrivate(
5757 "amdgpu-unroll-threshold-private",
5858 cl::desc("Unroll threshold for AMDGPU if private memory used in a loop"),
59 cl::init(2500), cl::Hidden);
59 cl::init(2000), cl::Hidden);
6060
6161 static cl::opt UnrollThresholdLocal(
6262 "amdgpu-unroll-threshold-local",
692692 CommonTTI.getUnrollingPreferences(L, SE, UP);
693693 }
694694
695 unsigned GCNTTIImpl::getUserCost(const User *U,
696 ArrayRef Operands) {
697 // Estimate extractelement elimination
698 if (const ExtractElementInst *EE = dyn_cast(U)) {
699 ConstantInt *CI = dyn_cast(EE->getOperand(1));
700 unsigned Idx = -1;
701 if (CI)
702 Idx = CI->getZExtValue();
703 return getVectorInstrCost(EE->getOpcode(), EE->getOperand(0)->getType(),
704 Idx);
705 }
706
707 // Estimate insertelement elimination
708 if (const InsertElementInst *IE = dyn_cast(U)) {
709 ConstantInt *CI = dyn_cast(IE->getOperand(2));
710 unsigned Idx = -1;
711 if (CI)
712 Idx = CI->getZExtValue();
713 return getVectorInstrCost(IE->getOpcode(), IE->getType(), Idx);
714 }
715
716 // Estimate different intrinsics, e.g. llvm.fabs
717 if (const IntrinsicInst *II = dyn_cast(U)) {
718 SmallVector Args(II->arg_operands());
719 FastMathFlags FMF;
720 if (auto *FPMO = dyn_cast(II))
721 FMF = FPMO->getFastMathFlags();
722 return getIntrinsicInstrCost(II->getIntrinsicID(), II->getType(), Args,
723 FMF);
724 }
725 return BaseT::getUserCost(U, Operands);
726 }
727
695728 unsigned R600TTIImpl::getHardwareNumberOfRegisters(bool Vec) const {
696729 return 4 * 128; // XXX - 4 channels. Should these count as vector instead?
697730 }
203203 bool areInlineCompatible(const Function *Caller,
204204 const Function *Callee) const;
205205
206 unsigned getInliningThresholdMultiplier() { return 7; }
206 unsigned getInliningThresholdMultiplier() { return 9; }
207207
208208 int getInlinerVectorBonusPercent() { return 0; }
209209
213213 int getMinMaxReductionCost(Type *Ty, Type *CondTy,
214214 bool IsPairwiseForm,
215215 bool IsUnsigned);
216 unsigned getUserCost(const User *U, ArrayRef Operands);
216217 };
217218
218219 class R600TTIImpl final : public BasicTTIImplBase {
0 ; RUN: opt -cost-model -analyze -mtriple=amdgcn-unknown-amdhsa %s | FileCheck -check-prefixes=GCN,CI %s
1 ; RUN: opt -cost-model -analyze -mtriple=amdgcn-unknown-amdhsa -mcpu=fiji %s | FileCheck -check-prefixes=GCN,VI %s
2 ; RUN: opt -cost-model -analyze -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx900 %s | FileCheck -check-prefixes=GCN,GFX9 %s
1 ; RUN: opt -cost-model -analyze -mtriple=amdgcn-unknown-amdhsa -mcpu=fiji %s | FileCheck -check-prefixes=GCN,GFX89 %s
2 ; RUN: opt -cost-model -analyze -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx900 %s | FileCheck -check-prefixes=GCN,GFX89 %s
3 ; RUN: opt -cost-model -cost-kind=code-size -analyze -mtriple=amdgcn-unknown-amdhsa %s | FileCheck -check-prefixes=GCN,CI %s
4 ; RUN: opt -cost-model -cost-kind=code-size -analyze -mtriple=amdgcn-unknown-amdhsa -mcpu=fiji %s | FileCheck -check-prefixes=GCN,GFX89 %s
5 ; RUN: opt -cost-model -cost-kind=code-size -analyze -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx900 %s | FileCheck -check-prefixes=GCN,GFX89 %s
6
37
48 ; GCN: 'extractelement_v2i32'
59 ; GCN: estimated cost of 0 for {{.*}} extractelement <2 x i32>
112116
113117 ; GCN: 'extractelement_0_v2i16':
114118 ; CI: estimated cost of 1 for {{.*}} extractelement <2 x i16> %vec, i16 0
115 ; VI: estimated cost of 0 for {{.*}} extractelement <2 x i16>
116 ; GFX9: estimated cost of 0 for {{.*}} extractelement <2 x i16>
119 ; GFX89: estimated cost of 0 for {{.*}} extractelement <2 x i16>
117120 define amdgpu_kernel void @extractelement_0_v2i16(i16 addrspace(1)* %out, <2 x i16> addrspace(1)* %vaddr) {
118121 %vec = load <2 x i16>, <2 x i16> addrspace(1)* %vaddr
119122 %elt = extractelement <2 x i16> %vec, i16 0
0 ; RUN: opt -cost-model -analyze -mtriple=amdgcn-unknown-amdhsa < %s | FileCheck %s
1 ; RUN: opt -cost-model -cost-kind=code-size -analyze -mtriple=amdgcn-unknown-amdhsa < %s | FileCheck %s
12
2 ; CHECK: 'fabs_f32'
3 ; CHECK-LABEL: 'fabs_f32'
34 ; CHECK: estimated cost of 0 for {{.*}} call float @llvm.fabs.f32
45 define amdgpu_kernel void @fabs_f32(float addrspace(1)* %out, float addrspace(1)* %vaddr) #0 {
56 %vec = load float, float addrspace(1)* %vaddr
89 ret void
910 }
1011
11 ; CHECK: 'fabs_v2f32'
12 ; CHECK-LABEL: 'fabs_v2f32'
1213 ; CHECK: estimated cost of 0 for {{.*}} call <2 x float> @llvm.fabs.v2f32
1314 define amdgpu_kernel void @fabs_v2f32(<2 x float> addrspace(1)* %out, <2 x float> addrspace(1)* %vaddr) #0 {
1415 %vec = load <2 x float>, <2 x float> addrspace(1)* %vaddr
1718 ret void
1819 }
1920
20 ; CHECK: 'fabs_v3f32'
21 ; CHECK-LABEL: 'fabs_v3f32'
2122 ; CHECK: estimated cost of 0 for {{.*}} call <3 x float> @llvm.fabs.v3f32
2223 define amdgpu_kernel void @fabs_v3f32(<3 x float> addrspace(1)* %out, <3 x float> addrspace(1)* %vaddr) #0 {
2324 %vec = load <3 x float>, <3 x float> addrspace(1)* %vaddr
2627 ret void
2728 }
2829
29 ; CHECK: 'fabs_v5f32'
30 ; CHECK-LABEL: 'fabs_v5f32'
3031 ; CHECK: estimated cost of 0 for {{.*}} call <5 x float> @llvm.fabs.v5f32
3132 define amdgpu_kernel void @fabs_v5f32(<5 x float> addrspace(1)* %out, <5 x float> addrspace(1)* %vaddr) #0 {
3233 %vec = load <5 x float>, <5 x float> addrspace(1)* %vaddr
3536 ret void
3637 }
3738
38 ; CHECK: 'fabs_f64'
39 ; CHECK-LABEL: 'fabs_f64'
3940 ; CHECK: estimated cost of 0 for {{.*}} call double @llvm.fabs.f64
4041 define amdgpu_kernel void @fabs_f64(double addrspace(1)* %out, double addrspace(1)* %vaddr) #0 {
4142 %vec = load double, double addrspace(1)* %vaddr
4445 ret void
4546 }
4647
47 ; CHECK: 'fabs_v2f64'
48 ; CHECK-LABEL: 'fabs_v2f64'
4849 ; CHECK: estimated cost of 0 for {{.*}} call <2 x double> @llvm.fabs.v2f64
4950 define amdgpu_kernel void @fabs_v2f64(<2 x double> addrspace(1)* %out, <2 x double> addrspace(1)* %vaddr) #0 {
5051 %vec = load <2 x double>, <2 x double> addrspace(1)* %vaddr
5354 ret void
5455 }
5556
56 ; CHECK: 'fabs_v3f64'
57 ; CHECK-LABEL: 'fabs_v3f64'
5758 ; CHECK: estimated cost of 0 for {{.*}} call <3 x double> @llvm.fabs.v3f64
5859 define amdgpu_kernel void @fabs_v3f64(<3 x double> addrspace(1)* %out, <3 x double> addrspace(1)* %vaddr) #0 {
5960 %vec = load <3 x double>, <3 x double> addrspace(1)* %vaddr
6263 ret void
6364 }
6465
65 ; CHECK: 'fabs_f16'
66 ; CHECK-LABEL: 'fabs_f16'
6667 ; CHECK: estimated cost of 0 for {{.*}} call half @llvm.fabs.f16
6768 define amdgpu_kernel void @fabs_f16(half addrspace(1)* %out, half addrspace(1)* %vaddr) #0 {
6869 %vec = load half, half addrspace(1)* %vaddr
7172 ret void
7273 }
7374
74 ; CHECK: 'fabs_v2f16'
75 ; CHECK-LABEL: 'fabs_v2f16'
7576 ; CHECK: estimated cost of 0 for {{.*}} call <2 x half> @llvm.fabs.v2f16
7677 define amdgpu_kernel void @fabs_v2f16(<2 x half> addrspace(1)* %out, <2 x half> addrspace(1)* %vaddr) #0 {
7778 %vec = load <2 x half>, <2 x half> addrspace(1)* %vaddr
8081 ret void
8182 }
8283
83 ; CHECK: 'fabs_v3f16'
84 ; CHECK-LABEL: 'fabs_v3f16'
8485 ; CHECK: estimated cost of 0 for {{.*}} call <3 x half> @llvm.fabs.v3f16
8586 define amdgpu_kernel void @fabs_v3f16(<3 x half> addrspace(1)* %out, <3 x half> addrspace(1)* %vaddr) #0 {
8687 %vec = load <3 x half>, <3 x half> addrspace(1)* %vaddr
0 ; RUN: opt -cost-model -analyze -mtriple=amdgcn-unknown-amdhsa %s | FileCheck -check-prefixes=GCN,CI %s
1 ; RUN: opt -cost-model -analyze -mtriple=amdgcn-unknown-amdhsa -mcpu=fiji %s | FileCheck -check-prefixes=GCN,VI %s
2 ; RUN: opt -cost-model -analyze -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx900 %s | FileCheck -check-prefixes=GCN,GFX9 %s
1 ; RUN: opt -cost-model -analyze -mtriple=amdgcn-unknown-amdhsa -mcpu=fiji %s | FileCheck -check-prefixes=GCN,GFX89 %s
2 ; RUN: opt -cost-model -analyze -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx900 %s | FileCheck -check-prefixes=GCN,GFX89 %s
3 ; RUN: opt -cost-model -cost-kind=code-size -analyze -mtriple=amdgcn-unknown-amdhsa %s | FileCheck -check-prefixes=GCN,CI %s
4 ; RUN: opt -cost-model -cost-kind=code-size -analyze -mtriple=amdgcn-unknown-amdhsa -mcpu=fiji %s | FileCheck -check-prefixes=GCN,GFX89 %s
5 ; RUN: opt -cost-model -cost-kind=code-size -analyze -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx900 %s | FileCheck -check-prefixes=GCN,GFX89 %s
36
47 ; GCN-LABEL: 'insertelement_v2i32'
58 ; GCN: estimated cost of 0 for {{.*}} insertelement <2 x i32>
2124
2225 ; GCN-LABEL: 'insertelement_0_v2i16'
2326 ; CI: estimated cost of 1 for {{.*}} insertelement <2 x i16>
24 ; VI: estimated cost of 0 for {{.*}} insertelement <2 x i16>
25 ; GFX9: estimated cost of 0 for {{.*}} insertelement <2 x i16>
27 ; GFX89: estimated cost of 0 for {{.*}} insertelement <2 x i16>
2628 define amdgpu_kernel void @insertelement_0_v2i16(<2 x i16> addrspace(1)* %out, <2 x i16> addrspace(1)* %vaddr) {
2729 %vec = load <2 x i16>, <2 x i16> addrspace(1)* %vaddr
2830 %insert = insertelement <2 x i16> %vec, i16 123, i16 0