llvm/test/Transforms/Inline/nonnull.ll
Philip Reames 64b906419e Teach InlineCost to account for a null check which can be folded away
If we have a caller that knows a particular argument can never be null, we can exploit this fact while simplifying values in the inline cost analysis. This has the effect of reducing the cost for inlining when a null check is present in the callee, but the value is known non null in the caller. In particular, any dependent control flow can be discounted from the cost estimate.

Note that we use the parameter attributes at the call site to memoize the analysis within the caller's code.  The setting of this attribute is done in InstCombine, the inline cost analysis just consumes it.  This is intentional and important because we want the inline cost analysis results to be easily cachable themselves.  We're not currently doing so, but initial results on LTO indicate this will quickly become important.

Differential Revision: http://reviews.llvm.org/D9129



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240828 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-26 20:51:17 +00:00

46 lines
923 B
LLVM

; RUN: opt -S -inline %s | FileCheck %s
declare void @foo()
declare void @bar()
define void @callee(i8* %arg) {
%cmp = icmp eq i8* %arg, null
br i1 %cmp, label %expensive, label %done
; This block is designed to be too expensive to inline. We can only inline
; callee if this block is known to be dead.
expensive:
call void @foo()
call void @foo()
call void @foo()
call void @foo()
call void @foo()
call void @foo()
call void @foo()
call void @foo()
call void @foo()
call void @foo()
ret void
done:
call void @bar()
ret void
}
; Positive test - arg is known non null
define void @caller(i8* nonnull %arg) {
; CHECK-LABEL: @caller
; CHECK: call void @bar()
call void @callee(i8* nonnull %arg)
ret void
}
; Negative test - arg is not known to be non null
define void @caller2(i8* %arg) {
; CHECK-LABEL: @caller2
; CHECK: call void @callee(
call void @callee(i8* %arg)
ret void
}