<div class="gmail_extra"><div class="gmail_quote">On Mon, Sep 10, 2012 at 1:35 AM, Nadav Rotem <span dir="ltr"><<a href="mailto:nrotem@apple.com" target="_blank" class="cremed">nrotem@apple.com</a>></span> wrote:<br>
<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 class="im"><br><div><div>On Sep 9, 2012, at 1:45 AM, Chandler Carruth <<a href="mailto:chandlerc@google.com" target="_blank" class="cremed">chandlerc@google.com</a>> wrote:</div>
<br><blockquote type="cite"><div style="font-family:Helvetica;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
My idea had been to extend the IR to directly represent the concept of this operation. Currently, we have a 'br' instruction to represent binary control flow selection, and we have a 'switch' instruction to represent N-way control flow selection. We also have 'select' to represent binary value selection, but no instruction to represent N-way value selection. I suggested adding a new instruction 'selectswitch' (or some better name) to support selecting over N values based on an integer much the way switch works.</div>
<br></blockquote></div><div><br></div></div><div>How would you use selectswitch ? Will it allows you to do things that you can't do today ?</div></div></blockquote><div><br></div><div>It will allow some of the speculative value-forwarding optimizations that currently fire on selects to also fire on the code paths where the current SimplifyCFG fires. For example, the forward-propagating constant folding done in the inliner can forward values through selects when the i1 variable is a constant. Before this pass, it would pick the correct sucessor basic block, but couldn't trace that through to the PHI-node and prove that only the one predecessor was live, thus collapsing the PHI node to a single incoming value. With this pass, everything is indirected through memory.</div>
<div><br></div><div>There are probably other places where this applies, but I expect most of them to take this form.</div><div><br></div><div>The second form, which i suspect is a touch less common, is allowing passes to know that a selectswitch could take on one of some small N number of values. If the operands are all constants, or are all the same etc, passes can simplify the reasoning about the selectswitch.</div>
</div></div>