[PATCH] D121341: [SystemZ] implement adjustInliningThreshold()
Jonas Paulsson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 9 15:22:27 PST 2022
jonpa updated this revision to Diff 414226.
jonpa added a comment.
Maybe add a test as well?
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D121341/new/
https://reviews.llvm.org/D121341
Files:
llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.h
llvm/test/CodeGen/SystemZ/inline-thresh-adjust.ll
Index: llvm/test/CodeGen/SystemZ/inline-thresh-adjust.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/SystemZ/inline-thresh-adjust.ll
@@ -0,0 +1,32 @@
+; RUN: opt < %s -mtriple=systemz-unknown -mcpu=z15 -inline -disable-output \
+; RUN: -debug-only=inline 2>&1 | FileCheck %s
+; REQUIRES: asserts
+;
+; Check that the inlining threshold is incremented for a function using an
+; argument only as a memcpy source.
+
+; CHECK: Inlining calls in: root_function
+; CHECK: Inlining (cost=-30, threshold=1012), Call: call void @leaf_function_A(i8* %Dst)
+; CHECK: Inlining (cost=-35, threshold=1687), Call: call void @leaf_function_B(i8* %Dst, i8* %Src)
+
+
+define void @leaf_function_A(i8* %Dst) {
+entry:
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %Dst, i8* undef, i64 16, i1 false)
+ ret void
+}
+
+define void @leaf_function_B(i8* %Dst, i8* %Src) {
+entry:
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %Dst, i8* %Src, i64 16, i1 false)
+ ret void
+}
+
+define void @root_function(i8* %Dst, i8* %Src) {
+entry:
+ call void @leaf_function_A(i8* %Dst)
+ call void @leaf_function_B(i8* %Dst, i8* %Src)
+ ret void
+}
+
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg)
Index: llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.h
===================================================================
--- llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.h
+++ llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.h
@@ -37,6 +37,7 @@
/// @{
unsigned getInliningThresholdMultiplier() { return 3; }
+ unsigned adjustInliningThreshold(const CallBase *CB) const;
InstructionCost getIntImmCost(const APInt &Imm, Type *Ty,
TTI::TargetCostKind CostKind);
Index: llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
===================================================================
--- llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
+++ llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
@@ -30,6 +30,42 @@
//
//===----------------------------------------------------------------------===//
+static bool isUsedAsMemCpySource(const Value *V, bool &OtherUse) {
+ bool UsedAsMemCpySource = false;
+ for (const User *U : V->users())
+ if (const Instruction *User = dyn_cast<Instruction>(U)) {
+ if (isa<BitCastInst>(User) || isa<GetElementPtrInst>(User)) {
+ UsedAsMemCpySource |= isUsedAsMemCpySource(User, OtherUse);
+ continue;
+ }
+ if (const MemCpyInst *Memcpy = dyn_cast<MemCpyInst>(User)) {
+ if (Memcpy->getOperand(1) == V && !Memcpy->isVolatile()) {
+ UsedAsMemCpySource = true;
+ continue;
+ }
+ }
+ OtherUse = true;
+ }
+ return UsedAsMemCpySource;
+}
+
+unsigned SystemZTTIImpl::adjustInliningThreshold(const CallBase *CB) const {
+ unsigned Bonus = 0;
+
+ // Increase the threshold if an incoming argument is used only as a memcpy
+ // source.
+ if (Function *Callee = CB->getCalledFunction())
+ for (Argument &Arg : Callee->args()) {
+ bool OtherUse = false;
+ if (isUsedAsMemCpySource(&Arg, OtherUse) && !OtherUse)
+ Bonus += 150;
+ }
+
+ LLVM_DEBUG(if (Bonus)
+ dbgs() << "++ SZTTI Adding inlining bonus: " << Bonus << "\n";);
+ return Bonus;
+}
+
InstructionCost SystemZTTIImpl::getIntImmCost(const APInt &Imm, Type *Ty,
TTI::TargetCostKind CostKind) {
assert(Ty->isIntegerTy());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121341.414226.patch
Type: text/x-patch
Size: 3567 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220309/66facdb9/attachment.bin>
More information about the llvm-commits
mailing list