<div dir="ltr">Thanks all.<div><br></div><div>David why do you say it is particularly bad IR (other than not having gone through SROA). Is it the multiple blocks for early returns? That is how I'm supporting early returns in the middle of a basic block. I couldn't find any other way.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 5, 2015 at 6:24 AM, David Jones <span dir="ltr"><<a href="mailto:djones@xtreme-eda.com" target="_blank">djones@xtreme-eda.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Data point:<br><br></div>I use (rarely) alloca in basic blocks other than the entry block, and it works.<br><br></div>The one point to be aware of: alloca is "cleaned up" only when the function returns. If you use alloca in a loop, and you have no other mechanism to deal with it, you will blow out your stack and segfault.<br><br></div>One way to deal with this is to use llvm.stacksave before the alloca ad llvm.stackrestore after you're done. These functions can serve to do "proper" middle-block allocations, creating temporary storage that is valid only as long as you need it.<br><br></div>Note to self: good call to do all of your "longer term" allocas in the entry block. Don't move them to inner blocks even if you think you can, as SROA won't touch them.<br><br><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 5, 2015 at 5:44 AM, David Chisnall <span dir="ltr"><<a href="mailto:David.Chisnall@cl.cam.ac.uk" target="_blank">David.Chisnall@cl.cam.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It's not great IR, but it doesn't look like it should actually crash, just (without SROA) produce comparatively bad code.  The alloca is only referenced in the basic block that it exists.  If this isn't expected to work, then we should probably improve the documentation of alloca in the language reference.<br>
<span><font color="#888888"><br>
David<br>
</font></span><div><div><br>
> On 5 Apr 2015, at 04:55, Eric Christopher <<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>> wrote:<br>
><br>
> Allocas not in the entry block are treated as dynamic allocas and not stack slots.<br>
><br>
><br>
> On Sat, Apr 4, 2015, 8:37 PM Dave Pitsbawn <<a href="mailto:dpitsbawn@gmail.com" target="_blank">dpitsbawn@gmail.com</a>> wrote:<br>
> Here is some IR that is working and executing as expected -- All allocas are in the first basic block, and only updates happen in other basic blocks.<br>
><br>
> define i32 @f() {<br>
> entry:<br>
>   %x = alloca i32<br>
>   store i32 333, i32* %x<br>
>   %i = alloca i32<br>
>   store i32 11, i32* %i<br>
>   br i1 true, label %if.then, label %if.else<br>
><br>
> if.then:                                          ; preds = %entry<br>
>   store i32 3, i32* %i<br>
>   %0 = load i32* %i<br>
>   ret i32 %0<br>
><br>
> if.else:                                          ; preds = %entry<br>
>   ret i32 2<br>
><br>
> if.end:                                           ; preds = %after_ret1, %after_<br>
> ret<br>
>   ret i32 1<br>
><br>
> after_ret:                                        ; No predecessors!<br>
>   br label %if.end<br>
><br>
> after_ret1:                                       ; No predecessors!<br>
>   br label %if.end<br>
><br>
> after_ret2:                                       ; No predecessors!<br>
>   ret i32 0<br>
> }<br>
><br>
> The following IR is slightly different in that the alloca is defined not in the first basic block:<br>
><br>
> define i32 @M() {<br>
> entry:<br>
>   %x = alloca i32<br>
>   store i32 333, i32* %x<br>
>   br i1 true, label %if.then, label %if.else<br>
><br>
> if.then:                                          ; preds = %entry<br>
>   %i = alloca i32<br>
>   store i32 3, i32* %i<br>
>   %0 = load i32* %i<br>
>   ret i32 %0<br>
><br>
> if.else:                                          ; preds = %entry<br>
>   ret i32 2<br>
><br>
> if.end:                                           ; preds = %after_ret1, %after_<br>
> ret<br>
>   ret i32 1<br>
><br>
> after_ret:                                        ; No predecessors!<br>
>   br label %if.end<br>
><br>
> after_ret1:                                       ; No predecessors!<br>
>   br label %if.end<br>
><br>
> after_ret2:                                       ; No predecessors!<br>
>   ret i32 0<br>
> }<br>
><br>
> This segfaults for me. The IR passes the function verifier. Can someone spot an error? I don't see any.<br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>