[PATCH] D14122: [SimplifyCFG] Trim duplicate basic blocks in switch cases

Dylan McKay via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 29 02:00:22 PDT 2015


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.

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.

In code (after the block prefix has been factored out).

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
}

Am I missing something?
​

On Thu, Oct 29, 2015 at 6:24 PM, Dylan McKay <dylanmckay34 at gmail.com> wrote:

> dylanmckay abandoned this revision.
> dylanmckay added a comment.
>
> 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).
>
> 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.
>
> Thanks for the reviews Sanjoy and Phillip, I will make sure to address all
> points in the next patch.
>
>
> http://reviews.llvm.org/D14122
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151029/be8f6202/attachment.html>


More information about the llvm-commits mailing list