<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Control Height Reduction Pass should not clone basic blocks generated by computed gotos"
   href="https://bugs.llvm.org/show_bug.cgi?id=50610">50610</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Control Height Reduction Pass should not clone basic blocks generated by computed gotos
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>lxfind@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24918" name="attach_24918" title="IR that can repro this bug">attachment 24918</a> <a href="attachment.cgi?id=24918&action=edit" title="IR that can repro this bug">[details]</a></span>
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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>