[llvm-bugs] [Bug 50610] New: Control Height Reduction Pass should not clone basic blocks generated by computed gotos

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jun 7 22:03:29 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50610

            Bug ID: 50610
           Summary: Control Height Reduction Pass should not clone basic
                    blocks generated by computed gotos
           Product: new-bugs
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: lxfind at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

Created attachment 24918
  --> https://bugs.llvm.org/attachment.cgi?id=24918&action=edit
IR that can repro this bug

Control Height Reduction Pass reduces conditional jumps in the hot path by
cloning blocks into hot path block and cold path block, so that it can thread
the hot path blocks together.
Unfortunately, we should not clone basic blocks generated by computed gotos.
Basic blocks generated by computed gotos, will have their address taken and
stored in a global variable; and in the function there will be a "indirect
branch" instruction pointing to those basic blocks.
These basic blocks cannot be cloned. Because the global block address list
variable can only point to one version of the block, not the cloned one. The
cloned version of the indirect branch will be pointing to the cloned basic
blocks, which are not referred through any addresses. SimplifyCFG will then
eventually come and remove these cloned basic blocks completely because BBs in
the indirect branch target list must have their address taken somewhere.

I attached an IR that we can use to reproduce this issue.
Run:

bin/opt -passes='require<profile-summary>,function(chr)' -S extract.ll -o
out.ll

In out.ll, you will see that all basic blocks from the computed goto got cloned
into .chr version, and these basic blocks are in trouble because they are
referred by indirect branch instruction but their addresses are not taken
anywhere. Hence they will be eventually removed by SimplifyCFG. One can confirm
this by running opt with -simplifycfg on out.ll and observe the output.

The conditions to trigger CHR is fairly complicated and my understanding of how
CHR works is also limited, hence I haven't been able to reduce the IR to a
smaller one.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210608/53ab2d18/attachment.html>


More information about the llvm-bugs mailing list