
This patch introduces four new string attributes: function-inline-cost, function-inline-threshold, call-inline-cost and call-threshold-bonus. These attributes allow you to selectively override some aspects of InlineCost analysis. That would allow us to test inliner separately from the InlineCost analysis. That could be useful when you're trying to write tests for inliner and you need to test some very specific situation, like "the inline cost has to be this high", or "the threshold has to be this low". Right now every time someone does that, they have get creative to come up with a way to make the InlineCost give them the number they need (like adding ~30 load/add pairs for a trivial test). This process can be somewhat tedious which can discourage some people from writing enough tests for their changes. Also, that results in tests that are fragile and can be easily broken without anyone noticing it because the test writer can't explicitly control what input the inliner will get from the inline cost analysis. These new attributes will alleviate those problems to an extent. Reviewed By: mtrofin Differential Revision: https://reviews.llvm.org/D109033
47 lines
1.2 KiB
LLVM
47 lines
1.2 KiB
LLVM
|
|
; RUN: opt < %s -passes='require<profile-summary>,cgscc(inline)' -inline-threshold=100 -inline-cold-callsite-threshold=0 -S | FileCheck %s
|
|
|
|
; This tests that a cold callsite gets the inline-cold-callsite-threshold
|
|
; and does not get inlined. Another callsite to an identical callee that
|
|
; is not cold gets inlined because cost is below the inline-threshold.
|
|
|
|
define void @callee() "function-inline-cost"="10" {
|
|
call void @extern()
|
|
ret void
|
|
}
|
|
|
|
declare void @extern()
|
|
declare i1 @ext(i32)
|
|
|
|
; CHECK-LABEL: caller
|
|
define i32 @caller(i32 %n) {
|
|
entry:
|
|
%cmp4 = icmp sgt i32 %n, 0
|
|
br i1 %cmp4, label %for.body, label %for.cond.cleanup
|
|
|
|
for.cond.cleanup:
|
|
ret i32 0
|
|
|
|
for.body:
|
|
%i.05 = phi i32 [ %inc, %for.inc ], [ 0, %entry ]
|
|
; CHECK: %call = tail call
|
|
%call = tail call zeroext i1 @ext(i32 %i.05)
|
|
; CHECK-NOT: call void @callee
|
|
; CHECK-NEXT: call void @extern
|
|
call void @callee()
|
|
br i1 %call, label %cold, label %for.inc, !prof !0
|
|
|
|
cold:
|
|
; CHECK: call void @callee
|
|
call void @callee()
|
|
br label %for.inc
|
|
|
|
for.inc:
|
|
%inc = add nuw nsw i32 %i.05, 1
|
|
%exitcond = icmp eq i32 %inc, %n
|
|
br i1 %exitcond, label %for.cond.cleanup, label %for.body
|
|
}
|
|
|
|
|
|
!0 = !{!"branch_weights", i32 1, i32 2000}
|