summaryrefslogtreecommitdiff
path: root/test/Transforms/Inline
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2013-12-13 07:59:56 +0000
committerChandler Carruth <chandlerc@gmail.com>2013-12-13 07:59:56 +0000
commit0bdc7cd5de8b11564ce7ab3af584b11a48b7ab51 (patch)
treeb50303b77431b0ab2b531eeb1374a613599b5ea3 /test/Transforms/Inline
parent2d39ad82bc64c5fd4536fe02bb6ab3f153a7dfac (diff)
downloadllvm-0bdc7cd5de8b11564ce7ab3af584b11a48b7ab51.tar.gz
llvm-0bdc7cd5de8b11564ce7ab3af584b11a48b7ab51.tar.bz2
llvm-0bdc7cd5de8b11564ce7ab3af584b11a48b7ab51.tar.xz
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197215 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/Inline')
-rw-r--r--test/Transforms/Inline/invoke-cost.ll45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/Transforms/Inline/invoke-cost.ll b/test/Transforms/Inline/invoke-cost.ll
new file mode 100644
index 0000000000..84d33ad551
--- /dev/null
+++ b/test/Transforms/Inline/invoke-cost.ll
@@ -0,0 +1,45 @@
+; 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
+}