Skip to content

Commit eff88db

Browse files
[EVM][InlineCost] Set threshold to a small value when BB is unreachable-terminated
For EVM, to return from the contract we are using different instructions (e.g. return, revert) which are followed by unreachable. In the Inliner heuristic, if BB is unreachable-terminated threshold is set to 0 and these callsites are unlikely to be inlined. Instead, add small threshold and continue to calculate cost model, since in some cases we benefit from inlining. Signed-off-by: Vladimir Radosavljevic <[email protected]>
1 parent 673ec53 commit eff88db

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

llvm/lib/Analysis/InlineCost.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,8 +1911,15 @@ InlineCostCallAnalyzer::getHotCallSiteThreshold(CallBase &Call,
19111911
void InlineCostCallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) {
19121912
// If no size growth is allowed for this inlining, set Threshold to 0.
19131913
if (!allowSizeGrowth(Call)) {
1914-
Threshold = 0;
1915-
return;
1914+
// EVM local change begin
1915+
if (Triple(Call.getFunction()->getParent()->getTargetTriple()).isEVM()) {
1916+
constexpr int UnreachableThreshold = 10;
1917+
Threshold = std::min(Threshold, UnreachableThreshold);
1918+
} else {
1919+
Threshold = 0;
1920+
return;
1921+
}
1922+
// EVM local change end
19161923
}
19171924

19181925
Function *Caller = Call.getCaller();

llvm/test/CodeGen/EVM/inline-in-bb-unreachable-terminated.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
target datalayout = "E-p:256:256-i256:256:256-S256-a:256:256"
44
target triple = "evm"
55

6-
; CHECK-LABEL: define private void @callee_inline
6+
; CHECK-NOT: define private void @callee_inline
77
define private void @callee_inline(i256 %arg) {
88
entry:
99
%itptr = inttoptr i256 %arg to ptr addrspace(5)
@@ -24,7 +24,7 @@ bb2:
2424
; CHECK-LABEL: define void @caller_inline1
2525
define void @caller_inline1(i256 %arg) {
2626
entry:
27-
; CHECK: call void @callee_inline(i256 %arg)
27+
; CHECK-NOT: call void @callee_inline(i256 %arg)
2828
call void @callee_inline(i256 %arg)
2929
%itptr = inttoptr i256 %arg to ptr addrspace(5)
3030
%load = load i256, ptr addrspace(5) %itptr, align 1
@@ -36,7 +36,7 @@ entry:
3636
; CHECK-LABEL: define void @caller_inline2
3737
define void @caller_inline2(i256 %arg1, i256 %arg2) {
3838
entry:
39-
; CHECK: call void @callee_inline(i256 %arg2)
39+
; CHECK-NOT: call void @callee_inline(i256 %arg2)
4040
call void @callee_inline(i256 %arg2)
4141
%itptr = inttoptr i256 %arg2 to ptr addrspace(5)
4242
%load = load i256, ptr addrspace(5) %itptr, align 1

0 commit comments

Comments
 (0)