1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00
llvm-mirror/test/Transforms/Inline/invoke-cost.ll
Chandler Carruth af9509e185 [inliner] Completely change (and fix) how the inline cost analysis
handles terminator instructions.

The inline cost analysis inheritted some pretty rough handling of
terminator insts from the original cost analysis, and then made it much,
much worse by factoring all of the important analyses into a separate
instruction visitor. That instruction visitor never visited the
terminator.

This works fine for things like conditional branches, but for many other
things we simply computed The Wrong Value. First example are
unconditional branches, which should be free but were counted as full
cost. This is most significant for conditional branches where the
condition simplifies and folds during inlining. We paid a 1 instruction
tax on every branch in a straight line specialized path. =[

Oh, we also claimed that the unreachable instruction had cost.

But it gets worse. Let's consider invoke. We never applied the call
penalty. We never accounted for the cost of the arguments. Nope. Worse
still, we didn't handle the *correctness* constraints of not inlining
recursive invokes, or exception throwing returns_twice functions. Oops.
See PR18206. Sadly, PR18206 requires yet another fix, but this
refactoring is at least a huge step in that direction.

llvm-svn: 197215
2013-12-13 07:59:56 +00:00

46 lines
1.0 KiB
LLVM

; RUN: opt -inline < %s -S -o - -inline-threshold=100 | FileCheck %s
target datalayout = "p:32:32"
@glbl = external global i32
declare void @f()
declare i32 @__gxx_personality_v0(...)
declare i8* @__cxa_begin_catch(i8*)
declare void @__cxa_end_catch()
declare void @_ZSt9terminatev()
define void @inner1() {
entry:
invoke void @f() to label %cont1 unwind label %terminate.lpad
cont1:
invoke void @f() to label %cont2 unwind label %terminate.lpad
cont2:
invoke void @f() to label %cont3 unwind label %terminate.lpad
cont3:
invoke void @f() to label %cont4 unwind label %terminate.lpad
cont4:
ret void
terminate.lpad:
landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
catch i8* null
call void @_ZSt9terminatev() noreturn nounwind
unreachable
}
define void @outer1() {
; CHECK-LABEL: @outer1(
;
; This call should not get inlined because inner1 actually calls a function
; many times, but it only does so through invoke as opposed to call.
;
; CHECK: call void @inner1
call void @inner1()
ret void
}