<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 20, 2016 at 11:51 PM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@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 dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Wed, Jul 20, 2016 at 6:04 PM, Daniel Berlin <span dir="ltr"><<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</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">FWIW: In gcc, the regeneration is a pair of mutually recursive functions, one called "create_expression_by_pieces" (which is the main interface), and one called "find_or_generate_expression"  (which in turn, calls create_expression_by_pieces for any operand that is itself a complex value expression).<div><br></div><div>Whether you do it similarly, or worklist it, you should have some invariant that each iteration guarantees or whatever.</div><div><br></div><div>I found mutual recursion easier because you can easily guarantee "at the end of this function we return the thing i need to place in this expression" for one of the functions, and there you go.</div></div></blockquote><div><br></div></span><div>Both of these approaches sound find to me, I'd just prefer avoiding the creation of unnecessary IR.</div><div><div class="h5"><div> </div></div></div></div></div></div></blockquote><div><br></div><div>Agreed.</div><div>You should build a list of instructions to insert, in order, and only once you are sure things will succeed, insert it.</div><div><br></div></div></div></div>