Skip to content

Commit 27e8c50

Browse files
committed
[SystemZ] Implement adjustInliningThreshold().
This patch boosts the inlining threshold for a particular type of functions that are using an incoming argument only as a memcpy source. Review: Ulrich Weigand Differential Revision: https://reviews.llvm.org/D121341
1 parent f407c9e commit 27e8c50

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,42 @@ using namespace llvm;
3030
//
3131
//===----------------------------------------------------------------------===//
3232

33+
static bool isUsedAsMemCpySource(const Value *V, bool &OtherUse) {
34+
bool UsedAsMemCpySource = false;
35+
for (const User *U : V->users())
36+
if (const Instruction *User = dyn_cast<Instruction>(U)) {
37+
if (isa<BitCastInst>(User) || isa<GetElementPtrInst>(User)) {
38+
UsedAsMemCpySource |= isUsedAsMemCpySource(User, OtherUse);
39+
continue;
40+
}
41+
if (const MemCpyInst *Memcpy = dyn_cast<MemCpyInst>(User)) {
42+
if (Memcpy->getOperand(1) == V && !Memcpy->isVolatile()) {
43+
UsedAsMemCpySource = true;
44+
continue;
45+
}
46+
}
47+
OtherUse = true;
48+
}
49+
return UsedAsMemCpySource;
50+
}
51+
52+
unsigned SystemZTTIImpl::adjustInliningThreshold(const CallBase *CB) const {
53+
unsigned Bonus = 0;
54+
55+
// Increase the threshold if an incoming argument is used only as a memcpy
56+
// source.
57+
if (Function *Callee = CB->getCalledFunction())
58+
for (Argument &Arg : Callee->args()) {
59+
bool OtherUse = false;
60+
if (isUsedAsMemCpySource(&Arg, OtherUse) && !OtherUse)
61+
Bonus += 150;
62+
}
63+
64+
LLVM_DEBUG(if (Bonus)
65+
dbgs() << "++ SZTTI Adding inlining bonus: " << Bonus << "\n";);
66+
return Bonus;
67+
}
68+
3369
InstructionCost SystemZTTIImpl::getIntImmCost(const APInt &Imm, Type *Ty,
3470
TTI::TargetCostKind CostKind) {
3571
assert(Ty->isIntegerTy());

llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class SystemZTTIImpl : public BasicTTIImplBase<SystemZTTIImpl> {
3737
/// @{
3838

3939
unsigned getInliningThresholdMultiplier() { return 3; }
40+
unsigned adjustInliningThreshold(const CallBase *CB) const;
4041

4142
InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
4243
TTI::TargetCostKind CostKind);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; RUN: opt < %s -mtriple=systemz-unknown -mcpu=z15 -inline -disable-output \
2+
; RUN: -debug-only=inline,systemztti 2>&1 | FileCheck %s
3+
; REQUIRES: asserts
4+
;
5+
; Check that the inlining threshold is incremented for a function using an
6+
; argument only as a memcpy source.
7+
8+
; CHECK: Inlining calls in: root_function
9+
; CHECK: Inlining {{.*}} Call: call void @leaf_function_A(i8* %Dst)
10+
; CHECK: ++ SZTTI Adding inlining bonus: 150
11+
; CHECK: Inlining {{.*}} Call: call void @leaf_function_B(i8* %Dst, i8* %Src)
12+
13+
define void @leaf_function_A(i8* %Dst) {
14+
entry:
15+
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %Dst, i8* undef, i64 16, i1 false)
16+
ret void
17+
}
18+
19+
define void @leaf_function_B(i8* %Dst, i8* %Src) {
20+
entry:
21+
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %Dst, i8* %Src, i64 16, i1 false)
22+
ret void
23+
}
24+
25+
define void @root_function(i8* %Dst, i8* %Src) {
26+
entry:
27+
call void @leaf_function_A(i8* %Dst)
28+
call void @leaf_function_B(i8* %Dst, i8* %Src)
29+
ret void
30+
}
31+
32+
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg)

0 commit comments

Comments
 (0)