Inliner: Do zero-cost inlines even if above a negative threshold (PR24851)
authorHans Wennborg <hans@hanshq.net>
Tue, 10 Nov 2015 09:47:48 +0000 (09:47 +0000)
committerHans Wennborg <hans@hanshq.net>
Tue, 10 Nov 2015 09:47:48 +0000 (09:47 +0000)
Differential Revision: http://reviews.llvm.org/D14499

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252595 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/InlineCost.cpp
test/Transforms/Inline/zero-cost.ll [new file with mode: 0644]

index 8169ce482461c151184b08f003145dc0244338a0..26f2e7ff504a8a6ad8f0b013ea7daad7643e1a77 100644 (file)
@@ -1296,7 +1296,7 @@ bool CallAnalyzer::analyzeCall(CallSite CS) {
   else if (NumVectorInstructions <= NumInstructions / 2)
     Threshold -= (FiftyPercentVectorBonus - TenPercentVectorBonus);
 
-  return Cost < Threshold;
+  return Cost <= std::max(0, Threshold);
 }
 
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
diff --git a/test/Transforms/Inline/zero-cost.ll b/test/Transforms/Inline/zero-cost.ll
new file mode 100644 (file)
index 0000000..8e7194a
--- /dev/null
@@ -0,0 +1,17 @@
+; RUN: opt -inline -S %s | FileCheck %s
+
+define void @f() {
+entry:
+  tail call void @g()
+  unreachable
+
+; CHECK-LABEL: @f
+; CHECK-NOT: call
+; CHECK: unreachable
+}
+
+define void @g() {
+entry:
+  unreachable
+}
+