[llvm] r206429 - Inline a function when the always_inline attribute

Nick Lewycky nlewycky at google.com
Wed Apr 16 17:51:11 PDT 2014


On 16 April 2014 17:21, Gerolf Hoflehner <ghoflehner at apple.com> wrote:

> Author: ghoflehner
> Date: Wed Apr 16 19:21:52 2014
> New Revision: 206429
>
> URL: http://llvm.org/viewvc/llvm-project?rev=206429&view=rev
> Log:
> Inline a function when the always_inline attribute
> is set even when it contains a indirect branch.
> The attribute overrules correctness concerns
> like the escape of a local block address.
>

False. Do not submit.

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.

This is for rdar://16501761
>
>
>
> Added:
>     llvm/trunk/test/Transforms/Inline/always-inline-attribute.ll
> Modified:
>     llvm/trunk/lib/Analysis/IPA/InlineCost.cpp
>     llvm/trunk/test/Transforms/Inline/always-inline.ll
>
> Modified: llvm/trunk/lib/Analysis/IPA/InlineCost.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IPA/InlineCost.cpp?rev=206429&r1=206428&r2=206429&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Analysis/IPA/InlineCost.cpp (original)
> +++ llvm/trunk/lib/Analysis/IPA/InlineCost.cpp Wed Apr 16 19:21:52 2014
> @@ -1300,8 +1300,14 @@ bool InlineCostAnalysis::isInlineViable(
>      F.getAttributes().hasAttribute(AttributeSet::FunctionIndex,
>                                     Attribute::ReturnsTwice);
>    for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI) {
> -    // Disallow inlining of functions which contain an indirect branch.
> -    if (isa<IndirectBrInst>(BI->getTerminator()))
> +    // Disallow inlining of functions which contain an indirect branch,
> +    // unless the always_inline attribute is set.
> +    // The attribute serves as a assertion that no local address
> +    // like a block label can escpape the function.
>

Typo, "escpape" -> "escape".

Nick

+    // Revisit enabling inlining for functions with indirect branches
> +    // when a more sophisticated espape/points-to analysis becomes
> available.
> +    if (isa<IndirectBrInst>(BI->getTerminator()) &&
> +        !F.hasFnAttribute(Attribute::AlwaysInline))
>        return false;
>
>      for (BasicBlock::iterator II = BI->begin(), IE = BI->end(); II != IE;
>
> Added: llvm/trunk/test/Transforms/Inline/always-inline-attribute.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/always-inline-attribute.ll?rev=206429&view=auto
>
> ==============================================================================
> --- llvm/trunk/test/Transforms/Inline/always-inline-attribute.ll (added)
> +++ llvm/trunk/test/Transforms/Inline/always-inline-attribute.ll Wed Apr
> 16 19:21:52 2014
> @@ -0,0 +1,26 @@
> +; RUN: opt < %s -O3 -S | FileCheck %s
> + at gv = external global i32
> +
> +define i32 @main() nounwind {
> +; CHECK-NOT: call i32 @foo
> +  %1 = load i32* @gv, align 4
> +  %2 = tail call i32 @foo(i32 %1)
> +  unreachable
> +}
> +
> +define internal i32 @foo(i32) alwaysinline {
> +  br label %2
> +
> +; <label>:2                                       ; preds = %8, %1
> +  %3 = phi i32 [ %0, %1 ], [ %10, %8 ]
> +  %4 = phi i8* [ blockaddress(@foo, %2), %1 ], [ %6, %8 ]
> +  %5 = icmp eq i32 %3, 1
> +  %6 = select i1 %5, i8* blockaddress(@foo, %8), i8* %4
> +  %7 = add nsw i32 %3, -1
> +  br label %8
> +
> +; <label>:8                                       ; preds = %8, %2
> +  %9 = phi i32 [ %7, %2 ], [ %10, %8 ]
> +  %10 = add nsw i32 %9, -1
> +  indirectbr i8* %6, [label %2, label %8]
> +}
>
> Modified: llvm/trunk/test/Transforms/Inline/always-inline.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/always-inline.ll?rev=206429&r1=206428&r2=206429&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Transforms/Inline/always-inline.ll (original)
> +++ llvm/trunk/test/Transforms/Inline/always-inline.ll Wed Apr 16 19:21:52
> 2014
> @@ -78,7 +78,7 @@ entry:
>    ret i32 %add
>  }
>
> -define i32 @inner5(i8* %addr) alwaysinline {
> +define i32 @inner5(i8* %addr) {
>  entry:
>    indirectbr i8* %addr, [ label %one, label %two ]
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140416/fe7ab764/attachment.html>


More information about the llvm-commits mailing list