<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 26, 2015 at 5:15 PM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</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"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">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><div>On Sat, Dec 26, 2015 at 7:08 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>> wrote:<br>
><br>
> On Dec 26, 2015 3:04 PM, "Connor Abbott" <<a href="mailto:cwabbott0@gmail.com" target="_blank">cwabbott0@gmail.com</a>> wrote:<br>
>><br>
>> On Sat, Dec 26, 2015 at 5:57 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>><br>
>> wrote:<br>
>> ><br>
>> > On Dec 26, 2015 2:22 PM, "Connor Abbott" <<a href="mailto:cwabbott0@gmail.com" target="_blank">cwabbott0@gmail.com</a>> wrote:<br></div></div></blockquote><div><br></div></span><div>[snip]<br></div><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>
>> >> 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></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>
</blockquote></div><br></div><div class="gmail_extra">Bah! I just realized why this won't work If I have<br><br></div><div class="gmail_extra">if (...) {<br></div><div class="gmail_extra"> // foo<br></div><div class="gmail_extra"> return;<br></div><div class="gmail_extra">}<br></div><div class="gmail_extra">// bar<br><br></div><div class="gmail_extra">it'll get replace with<br><br></div><div class="gmail_extra">if (...) {<br></div><div class="gmail_extra"> // foo<br></div><div class="gmail_extra">} else {<br></div><div class="gmail_extra"> // bar<br>}<br><br></div><div class="gmail_extra">and we're still left with the problem of where to place the return. I'm trying to get rid of it, so it seems natural to place it outside the function. However, bar might not have returned at the end. so we may need to keep going. For top-level, I thing this works ok because we can just pull the rest of the function into the else. However, for nested if's, it doesn't work. I guess I do need the return_flag for everything. Let's hope dead_cf does a good job...<br><br></div></div>