<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 26, 2015 at 4:59 PM, Connor Abbott <span dir="ltr"><<a href="mailto:cwabbott0@gmail.com" target="_blank">cwabbott0@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Sat, Dec 26, 2015 at 7:08 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
><br>
> On Dec 26, 2015 3:04 PM, "Connor Abbott" <<a href="mailto:cwabbott0@gmail.com">cwabbott0@gmail.com</a>> wrote:<br>
>><br>
>> On Sat, Dec 26, 2015 at 5:57 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
>> wrote:<br>
>> ><br>
>> > On Dec 26, 2015 2:22 PM, "Connor Abbott" <<a href="mailto:cwabbott0@gmail.com">cwabbott0@gmail.com</a>> wrote:<br></div></div></blockquote><div><br></div><div>[snip]<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
>> >> There are a few problems with this approach.<br>
>> >><br>
>> >> First off, imagine something like:<br>
>> >><br>
>> >> if (...) {<br>
>> >> if (...) return;<br>
>> >> }<br>
>> >> ...<br>
>> >><br>
>> >> If I'm reading this correctly, we'd lower this to:<br>
>> >><br>
>> >> if (...) {<br>
>> >> if (...) ;<br>
>> >> }<br>
>> >> ...<br>
>> ><br>
>> > Oops... You're right. I meant to add returns. This<br>
>> ><br>
>> > if (...) {<br>
>> > if (...) return;<br>
>> > // foo<br>
>> > }<br>
>> ><br>
>> > Should be lowered to<br>
>> ><br>
>> > if (...) {<br>
>> > if (...) {<br>
>> > } else {<br>
>> > // foo<br>
>> > }<br>
>> > return;<br>
>> > }<br>
>> ><br>
>> > Which we can then lower further.<br>
>><br>
>> I don't think that's correct though. What if there's stuff after the<br>
>> outer if? It'll only get executed if the outer if condition is false,<br>
>> instead of if either one is false. I think we really need the flag in<br>
>> this case.<br>
><br>
> If there's stuff in the outer if, it gets moved into the else<br>
<br>
</div></div>Stuff after the outer if, not in it.<br></blockquote><div><br></div><div>Right. I'm thinking what we probably want is a two-pass approach.<br><br></div><div>Pass 1: Loops. We recurs into all loops and lower returns to set the return flag and break. This pass goes top-down and depth-first to ensure that we hit the "if (return_flag) return" after the loop it belongs to. I also just realized that "if (return_flag return" needs to be inserted after the phi nodes. We'll need a new cursor helper for that.<br><br></div><div>Pass 2: If's not in loops. At this point, we can ignore loops completely since we've already lowered all of them and we need only consider blocks. This pass is a post-order bottom-up DFS. We look at if/else blocks and, if one of them has a return, move the stuff after the node into whichever case doesn't return and put a return after the node.<br><br></div><div>How does that sound?<br></div></div></div></div>