Skip to content

Commit 9b63a92

Browse files
authored
Implement areInlineCompatible for SystemZ using feature bitset (#132976)
## What? Implement `areInlineCompatible` for the SystemZ target using FeatureBitset comparison. ## Why? The default implementation in `TargetTransformInfoImpl.h` makes a string comparison and only inlines when the target-cpu and the target-features for caller and callee are the same. We are missing out on optimizations when the callee has a subset of features of the caller. ## How? Get the FeatureBitset of the caller and callee and check when callee is a subset or equal to the caller's features. It's a similar implementation to ARM, PowerPC... ## Testing? Test cases check for when the callee is a subset of the caller, when it's not a subset and when both are equals.
1 parent 9ce4557 commit 9b63a92

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,20 @@ bool SystemZTTIImpl::isLSRCostLess(const TargetTransformInfo::LSRCost &C1,
422422
C2.ScaleCost, C2.SetupCost);
423423
}
424424

425+
bool SystemZTTIImpl::areInlineCompatible(const Function *Caller,
426+
const Function *Callee) const {
427+
const TargetMachine &TM = getTLI()->getTargetMachine();
428+
429+
const FeatureBitset &CallerBits =
430+
TM.getSubtargetImpl(*Caller)->getFeatureBits();
431+
const FeatureBitset &CalleeBits =
432+
TM.getSubtargetImpl(*Callee)->getFeatureBits();
433+
434+
// Support only equal feature bitsets. Restriction should be relaxed in the
435+
// future to allow inlining when callee's bits are subset of the caller's.
436+
return CallerBits == CalleeBits;
437+
}
438+
425439
unsigned SystemZTTIImpl::getNumberOfRegisters(unsigned ClassID) const {
426440
bool Vector = (ClassID == 1);
427441
if (!Vector)

llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ class SystemZTTIImpl : public BasicTTIImplBase<SystemZTTIImpl> {
6262

6363
bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1,
6464
const TargetTransformInfo::LSRCost &C2);
65+
66+
bool areInlineCompatible(const Function *Caller,
67+
const Function *Callee) const;
68+
6569
/// @}
6670

6771
/// \name Vector TTI Implementations
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; RUN: opt < %s -mtriple=s390x-linux-gnu -S -passes=inline | FileCheck %s
2+
; RUN: opt < %s -mtriple=s390x-linux-gnu -S -passes='cgscc(inline)' | FileCheck %s
3+
; Check that we only inline when we have equal target attributes.
4+
5+
define i32 @foo() #0 {
6+
entry:
7+
%call = call i32 (...) @baz()
8+
ret i32 %call
9+
; CHECK-LABEL: foo
10+
; CHECK: call i32 (...) @baz()
11+
}
12+
13+
declare i32 @baz(...) #0
14+
15+
define i32 @bar() #1 {
16+
entry:
17+
%call = call i32 @foo()
18+
ret i32 %call
19+
; CHECK-LABEL: bar
20+
; CHECK: call i32 @foo()
21+
}
22+
23+
define i32 @qux() #0 {
24+
entry:
25+
%call = call i32 @foo()
26+
ret i32 %call
27+
; CHECK-LABEL: qux
28+
; CHECK: call i32 (...) @baz()
29+
}
30+
31+
define i32 @quux() #2 {
32+
entry:
33+
%call = call i32 @bar()
34+
ret i32 %call
35+
; CHECK-LABEL: quux
36+
; CHECK: call i32 @bar()
37+
}
38+
39+
40+
attributes #0 = { "target-cpu"="generic" "target-features"="+guarded-storage" }
41+
attributes #1 = { "target-cpu"="generic" "target-features"="+guarded-storage,+enhanced-sort" }
42+
attributes #2 = { "target-cpu"="generic" "target-features"="+concurrent-functions" }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if not "SystemZ" in config.root.targets:
2+
config.unsupported = True

0 commit comments

Comments
 (0)