<br><br><div class="gmail_quote"><div dir="ltr">On Thu, May 25, 2017, 8:43 AM James Molloy <<a href="mailto:James.Molloy@arm.com">James.Molloy@arm.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div style="word-wrap:break-word">
<div>PHIs are lowered by inserting COPYs into each predecessor. Switches only want to generate control flow, nothing else, so the theoretical insertion point for the COPY is above the switch.</div></div></blockquote></div><div><br></div><div>Usually edges are split if necessary.</div><div><br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">
<div><br>
</div>
<div>It would be possible to do what you suggest by manually splitting the switch up into its constituent compares (producing a binary search tree) with each leaf jumping to the same destination. But in that case each leaf is in a different basic block so you
 don’t have duplicate arcs any more :)</div></div><div style="word-wrap:break-word">
<div><br>
<blockquote type="cite">
<div>On 25 May 2017, at 16:36, Daniel Berlin <<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>> wrote:</div>
<br class="m_2330768480050415949Apple-interchange-newline">
<div>
<div dir="ltr"><br>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, May 25, 2017 at 8:24 AM, James Molloy <span dir="ltr">
<<a href="mailto:James.Molloy@arm.com" target="_blank">James.Molloy@arm.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div style="word-wrap:break-word">[+my non-arm account]
<div><br>
</div>
<div>Hi,</div>
<div><br>
</div>
<div>I believe I have a testcase for that too. The key is the word “conflicting” - we can have multiple edges from the same predecessor, but to be well formed all phi values for those arcs must be the same. The verifier checks this, if I recall.<br>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>Interesting.  I guess that is because it doesn't know how to map them back to the real edges or something.</div>
<div><br>
</div>
<div>IE:<br>
<div> define i32 @f3(i32 %x) {</div>
<div> bb0:<br>
</div>
<div>   switch i32 %x, label %bb1 [ </div>
<div>i32 0, label %bb2</div>
<div>i32 1, label %bb2</div>
<div>]</div>
<div> bb1:</div>
<div>   br label %bb2</div>
<div> bb2:</div>
<div>   %cond = phi i32 [ 0, %bb1 ], [ 0, %bb0 ], [ 1, %bb0 ]</div>
<div>   %foo = add i32 %cond, %x</div>
<div>   ret i32 %foo</div>
<div> }<br>
</div>
</div>
<div> <br>
</div>
<div><br>
</div>
<div>IE %cond = phi i32 [ 0, %bb1 ], [ 0, %bb0 ], [ 1, %bb0 ]</div>
<div><br>
</div>
<div>should be valid, but you are right, it is not, LLVM requires it to be</div>
<div>
<div><br>
</div>
<div> %cond = phi i32 [ 0, %bb1 ], [ %x, %bb0 ], [ %x, %bb0 ]</div>
</div>
<div><br>
</div>
<div>(In the above, i know i could eliminate the add along two paths if i could make a phi node with different values for each of the edges)</div>
<div><br>
</div>
<div><br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div style="word-wrap:break-word">
<div>I’ll make sure there’s a testcase at least for the full expected behaviour (this pass is off by default at the moment so there’s no panic about trunk miscompiling).</div>
<span class="m_2330768480050415949gmail-HOEnZb"><font color="#888888">
<div><br>
</div>
<div>James</div>
</font></span>
<div>
<div class="m_2330768480050415949gmail-h5">
<div><br>
</div>
<div>
<div>
<blockquote type="cite">
<div>On 25 May 2017, at 16:11, Daniel Berlin <<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>> wrote:</div>
<br class="m_2330768480050415949gmail-m_1444340689649942015Apple-interchange-newline">
<div>
<div dir="ltr">(That comment applies mostly to newgvn).
<div><br>
</div>
<div>In your case, i believe the code is just wrong:<br>
<br>
</div>
<div>
<div>/ This assumes the PHI is already well-formed and there aren't conflicting</div>
<div>    // incoming values for the same block.</div>
<div>    for (auto *B : Blocks)</div>
<div>      Values.push_back(PN->getIncomingValueForBlock(B))</div>
</div>
<div><br>
</div>
<div>It's 100% completely and definitely possible for a phi to have two values incoming from the same block, actually, regardless of whether it's a self block or not.</div>
<div>This happens using switch statements.</div>
<div>I believe we even have some testcases in newgvn for multiple edges from same incoming block.</div>
<div><br>
</div>
<div>So yeah, you have to handle them here.</div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, May 25, 2017 at 8:08 AM, 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote"><span>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span><br>
----------------<br>
</span><span>dberlin wrote:<br>
> I'm curious why you think you need stable sort here as opposed to regular<br>
><br>
</span>I don't. Changed.<br>
<div class="m_2330768480050415949gmail-m_1444340689649942015m_-7927023127036086712HOEnZb">
<div class="m_2330768480050415949gmail-m_1444340689649942015m_-7927023127036086712h5"><br>
</div>
</div>
</blockquote>
<div><br>
</div>
</span>
<div>(i'm offsite today, but someone should test this in newgvn too if i'm right).</div>
<div><br>
</div>
<div>Do we allow switch statements with multiple edges to ourself?<br>
<br>
ie</div>
<div><br>
</div>
<div>bb1:<br>
<br>
switch <whatever> [</div>
<div>i32 0 : label bb1</div>
<div>i32 1: label bb1 ]</div>
<div><br>
</div>
<div><br>
</div>
<div>(which, after propagation,  could cause a phi with different operands and the same incoming blocks)</div>
<div>If so, either we need stable sorts, or a better ordering of incoming blocks, because the pointer equality we use will not definitely sort them into a consistent order</div>
<div> </div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
<span class="m_2330768480050415949gmail-">IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person,
 use it for any purpose, or store or copy the information in any medium. Thank you.
</span></div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose,
 or store or copy the information in any medium. Thank you.
</div></blockquote></div>