<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">I’m not sure if the prefix merging is possible - I’ve got it to the point where SimplifyCFG recognizes common instructions in the basic block head, factors it into a separate block, which is then directly branched to by the switch instruction.</p>
<p style="margin:0px 0px 1.2em!important">The problem is that a branch to the different tails needs to be made via a PHI node. Using this, there needs to be distinct predecessors in order to differentiate between the two head blocks. Of course, the problem is that both code paths into the common block come from a single switch statement in a single basic block.</p>
<p style="margin:0px 0px 1.2em!important">In code (after the block prefix has been factored out).</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code class="hljs language-llvm" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);border-radius:3px;display:inline;background-color:rgb(248,248,248);white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;color:rgb(77,77,76);padding:0.5em;background:white">declare void @foo();

define void @main() {
entry:
    switch i32 %1, label %join [

        i32 1, label %common_head
        i32 2, label %common_head
    ]

; the factored out head common to tail1 and tail2
common_head:
    call void foo()
    ; SEE HERE: How to distinguish between branches from same basic block
    %label_to = phi label [%tail1, %entry], [%tail2, %entry]
    br %label_to

tail1: unreachable ; stub
tail2: unreachable ; stub

join:
    ret void
}
</code></pre>
<p style="margin:0px 0px 1.2em!important">Am I missing something?</p>
<div title="MDH:SSdtIG5vdCBzdXJlIGlmIHRoZSBwcmVmaXggbWVyZ2luZyBpcyBwb3NzaWJsZSAtIEkndmUgZ290
IGl0IHRvIHRoZSBwb2ludCB3aGVyZSBTaW1wbGlmeUNGRyByZWNvZ25pemVzIGNvbW1vbiBpbnN0
cnVjdGlvbnMgaW4gdGhlIGJhc2ljIGJsb2NrIGhlYWQsIGZhY3RvcnMgaXQgaW50byBhIHNlcGFy
YXRlIGJ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wOyAmbmJzcDsgJm5ic3A7ICZuYnNwOyBpMzIg
MiwgbGFiZWwgJWNvbW1vbl9oZWFkPC9kaXY+PGRpdj4mbmJzcDsgJm5ic3A7IF08L2Rpdj48ZGl2
Pjxicj48L2Rpdj48ZGl2PjsgdGhlIGZhY3RvcmVkIG91dCBoZWFkIGNvbW1vbiB0byB0YWlsMSBh
bmQgdGFpbDI8L2Rpdj48ZGl2PmNvbW1vbl9oZWFkOjwvZGl2PjxkaXY+Jm5ic3A7ICZuYnNwOyBj
YWxsIHZvaWQgZm9vKCk8L2Rpdj48ZGl2PiZuYnNwOyAmbmJzcDsgOyBTRUUgSEVSRTogSG93IHRv
IGRpc3Rpbmd1aXNoIGJldHdlZW4gYnJhbmNoZXMgZnJvbSBzYW1lIGJhc2ljIGJsb2NrPC9kaXY+
PGRpdj4mbmJzcDsgJm5ic3A7ICVsYWJlbF90byA9IHBoaSBsYWJlbCBbJXRhaWwxLCAlZW50cnld
LCBbJXRhaWwyLCAlZW50cnldPC9kaXY+PGRpdj4mbmJzcDsgJm5ic3A7IGJyICVsYWJlbF90bzwv
ZGl2PjxkaXY+PGJyPjwvZGl2PjxkaXY+dGFpbDE6IHVucmVhY2hhYmxlIDsgc3R1YjwvZGl2Pjxk
aXY+dGFpbDI6IHVucmVhY2hhYmxlIDsgc3R1YjwvZGl2PjxkaXY+PGJyPjwvZGl2PjxkaXY+am9p
bjo8L2Rpdj48ZGl2PiZuYnNwOyAmbmJzcDsgcmV0IHZvaWQ8L2Rpdj48ZGl2Pn08L2Rpdj48ZGl2
PmBgYDwvZGl2PjxkaXY+PGJyPjwvZGl2PjxkaXY+QW0gSSBtaXNzaW5nIHNvbWV0aGluZz88L2Rp
dj4=" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0">​</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 29, 2015 at 6:24 PM, Dylan McKay <span dir="ltr"><<a href="mailto:dylanmckay34@gmail.com" target="_blank">dylanmckay34@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">dylanmckay abandoned this revision.<br>
dylanmckay added a comment.<br>
<br>
Upon further reflection, I believe regular expressions are the best choice (as the x86 tests shouldn't care about the names of basic blocks - they should only care that i.e. the switch statements are converted to selects).<br>
<br>
I will fix the tests properly, remove the extraneous command line param, generalise to a basic block prefix merge optimisation and open a new diff once this is done.<br>
<br>
Thanks for the reviews Sanjoy and Phillip, I will make sure to address all points in the next patch.<br>
<br>
<br>
<a href="http://reviews.llvm.org/D14122" rel="noreferrer" target="_blank">http://reviews.llvm.org/D14122</a><br>
<br>
<br>
<br>
</blockquote></div><br></div>