<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 16 April 2014 17:21, Gerolf Hoflehner <span dir="ltr"><<a href="mailto:ghoflehner@apple.com" target="_blank">ghoflehner@apple.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ghoflehner<br>
Date: Wed Apr 16 19:21:52 2014<br>
New Revision: 206429<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=206429&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=206429&view=rev</a><br>
Log:<br>
Inline a function when the always_inline attribute<br>
is set even when it contains a indirect branch.<br>
The attribute overrules correctness concerns<br>
like the escape of a local block address.<br></blockquote><div><br></div><div>False. Do not submit.</div><div><br></div><div>If you want to inline functions that contain indirect branches, you need to teach the inliner how to do it correctly. This has the added bonus that we'll then be able to inline regular functions with indirect branches too.</div>

<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This is for rdar://16501761<br>
<br>
<br>
<br>
Added:<br>
    llvm/trunk/test/Transforms/Inline/always-inline-attribute.ll<br>
Modified:<br>
    llvm/trunk/lib/Analysis/IPA/InlineCost.cpp<br>
    llvm/trunk/test/Transforms/Inline/always-inline.ll<br>
<br>
Modified: llvm/trunk/lib/Analysis/IPA/InlineCost.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IPA/InlineCost.cpp?rev=206429&r1=206428&r2=206429&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IPA/InlineCost.cpp?rev=206429&r1=206428&r2=206429&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/lib/Analysis/IPA/InlineCost.cpp (original)<br>
+++ llvm/trunk/lib/Analysis/IPA/InlineCost.cpp Wed Apr 16 19:21:52 2014<br>
@@ -1300,8 +1300,14 @@ bool InlineCostAnalysis::isInlineViable(<br>
     F.getAttributes().hasAttribute(AttributeSet::FunctionIndex,<br>
                                    Attribute::ReturnsTwice);<br>
   for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI) {<br>
-    // Disallow inlining of functions which contain an indirect branch.<br>
-    if (isa<IndirectBrInst>(BI->getTerminator()))<br>
+    // Disallow inlining of functions which contain an indirect branch,<br>
+    // unless the always_inline attribute is set.<br>
+    // The attribute serves as a assertion that no local address<br>
+    // like a block label can escpape the function.<br></blockquote><div><br></div><div>Typo, "escpape" -> "escape".</div><div><br></div><div>Nick</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


+    // Revisit enabling inlining for functions with indirect branches<br>
+    // when a more sophisticated espape/points-to analysis becomes available.<br>
+    if (isa<IndirectBrInst>(BI->getTerminator()) &&<br>
+        !F.hasFnAttribute(Attribute::AlwaysInline))<br>
       return false;<br>
<br>
     for (BasicBlock::iterator II = BI->begin(), IE = BI->end(); II != IE;<br>
<br>
Added: llvm/trunk/test/Transforms/Inline/always-inline-attribute.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/always-inline-attribute.ll?rev=206429&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/always-inline-attribute.ll?rev=206429&view=auto</a><br>


==============================================================================<br>
--- llvm/trunk/test/Transforms/Inline/always-inline-attribute.ll (added)<br>
+++ llvm/trunk/test/Transforms/Inline/always-inline-attribute.ll Wed Apr 16 19:21:52 2014<br>
@@ -0,0 +1,26 @@<br>
+; RUN: opt < %s -O3 -S | FileCheck %s<br>
+@gv = external global i32<br>
+<br>
+define i32 @main() nounwind {<br>
+; CHECK-NOT: call i32 @foo<br>
+  %1 = load i32* @gv, align 4<br>
+  %2 = tail call i32 @foo(i32 %1)<br>
+  unreachable<br>
+}<br>
+<br>
+define internal i32 @foo(i32) alwaysinline {<br>
+  br label %2<br>
+<br>
+; <label>:2                                       ; preds = %8, %1<br>
+  %3 = phi i32 [ %0, %1 ], [ %10, %8 ]<br>
+  %4 = phi i8* [ blockaddress(@foo, %2), %1 ], [ %6, %8 ]<br>
+  %5 = icmp eq i32 %3, 1<br>
+  %6 = select i1 %5, i8* blockaddress(@foo, %8), i8* %4<br>
+  %7 = add nsw i32 %3, -1<br>
+  br label %8<br>
+<br>
+; <label>:8                                       ; preds = %8, %2<br>
+  %9 = phi i32 [ %7, %2 ], [ %10, %8 ]<br>
+  %10 = add nsw i32 %9, -1<br>
+  indirectbr i8* %6, [label %2, label %8]<br>
+}<br>
<br>
Modified: llvm/trunk/test/Transforms/Inline/always-inline.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/always-inline.ll?rev=206429&r1=206428&r2=206429&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/always-inline.ll?rev=206429&r1=206428&r2=206429&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/test/Transforms/Inline/always-inline.ll (original)<br>
+++ llvm/trunk/test/Transforms/Inline/always-inline.ll Wed Apr 16 19:21:52 2014<br>
@@ -78,7 +78,7 @@ entry:<br>
   ret i32 %add<br>
 }<br>
<br>
-define i32 @inner5(i8* %addr) alwaysinline {<br>
+define i32 @inner5(i8* %addr) {<br>
 entry:<br>
   indirectbr i8* %addr, [ label %one, label %two ]<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>