Skip to content

Commit 6d0cfbc

Browse files
authored
[PPC] Implement areInlineCompatible (#126562)
After the default implementation swap from #117493, where `areInlineCompatible` checks if the callee features are a subset of caller features. This is not a safe assumption in general on PPC. We fallback to check for strict feature set equality for now, and see what improvements we can make.
1 parent 911e94c commit 6d0cfbc

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,20 @@ PPCTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
895895
return BaseT::getIntrinsicInstrCost(ICA, CostKind);
896896
}
897897

898+
bool PPCTTIImpl::areInlineCompatible(const Function *Caller,
899+
const Function *Callee) const {
900+
const TargetMachine &TM = getTLI()->getTargetMachine();
901+
902+
const FeatureBitset &CallerBits =
903+
TM.getSubtargetImpl(*Caller)->getFeatureBits();
904+
const FeatureBitset &CalleeBits =
905+
TM.getSubtargetImpl(*Callee)->getFeatureBits();
906+
907+
// Check that targets features are exactly the same. We can revisit to see if
908+
// we can improve this.
909+
return CallerBits == CalleeBits;
910+
}
911+
898912
bool PPCTTIImpl::areTypesABICompatible(const Function *Caller,
899913
const Function *Callee,
900914
const ArrayRef<Type *> &Types) const {

llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h

+2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ class PPCTTIImpl : public BasicTTIImplBase<PPCTTIImpl> {
139139
bool UseMaskForCond = false, bool UseMaskForGaps = false);
140140
InstructionCost getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
141141
TTI::TargetCostKind CostKind);
142+
bool areInlineCompatible(const Function *Caller,
143+
const Function *Callee) const;
142144
bool areTypesABICompatible(const Function *Caller, const Function *Callee,
143145
const ArrayRef<Type *> &Types) const;
144146
bool hasActiveVectorLength(unsigned Opcode, Type *DataType,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
; RUN: opt < %s -mtriple=powerpc64le-ibm-linux-gnu -S -passes=inline | FileCheck %s
2+
; RUN: opt < %s -mtriple=powerpc64le-ibm-linux-gnu -S -passes='cgscc(inline)' | FileCheck %s
3+
4+
target datalayout = "E-m:e-i64:64-n32:64"
5+
target triple = "powerpc64le-ibm-linux-gnu"
6+
7+
declare void @inlined()
8+
9+
define void @explicit() #0 {
10+
; CHECK-LABEL: explicit
11+
; CHECK: entry
12+
; CHECK-NEXT: call void @not_compatible1()
13+
; CHECK-NEXT: call void @inlined()
14+
entry:
15+
call void @not_compatible1()
16+
call void @compatible1()
17+
ret void
18+
}
19+
20+
define void @not_compatible1() #1 {
21+
entry:
22+
call i32 @inlined()
23+
ret void
24+
}
25+
26+
define void @compatible1() #0 {
27+
entry:
28+
call void @inlined()
29+
ret void
30+
}
31+
32+
define void @default() #3 {
33+
; CHECK-LABEL: default
34+
; CHECK: entry
35+
; CHECK-NEXT: call void @not_compatible2()
36+
; CHECK-NEXT: call void @inlined()
37+
entry:
38+
call void @not_compatible2()
39+
call void @compatible2()
40+
ret void
41+
}
42+
43+
define void @not_compatible2() #4 {
44+
entry:
45+
call void @inlined()
46+
ret void
47+
}
48+
49+
define void @compatible2() #5 {
50+
entry:
51+
call void @inlined()
52+
ret void
53+
}
54+
55+
; explicit
56+
attributes #0 = { "target-cpu"="pwr7" "target-features"="+allow-unaligned-fp-access" }
57+
attributes #1 = { "target-cpu"="pwr7" "target-features"="-allow-unaligned-fp-access" }
58+
59+
; pwr7 by default implies +vsx
60+
attributes #3 = { "target-cpu"="pwr7" }
61+
attributes #4 = { "target-cpu"="pwr7" "target-features"="-vsx" }
62+
attributes #5 = { "target-cpu"="pwr7" "target-features"="+vsx" }
63+

0 commit comments

Comments
 (0)