<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 - verifyFunction spends too much time validating module metadata in +asserts builds"
   href="https://bugs.llvm.org/show_bug.cgi?id=47712">47712</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>verifyFunction spends too much time validating module metadata in +asserts builds
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Core LLVM classes
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>rnk@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>aprantl@apple.com, hans@chromium.org, llvm-bugs@lists.llvm.org, nicolasweber@gmx.de, spatel+llvm@rotateright.com, vsk@apple.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I was profiling LLVM for other reasons and accidentally used a build with
assertions enabled. What I discovered is that, if you compile PassBuilder.cpp
with assertions, most of the time is spent in the verifier, mostly due to
asserts in SLPVectorizer and LoopVectorizer. There are 187,486 samples overall,
and 131,698 of them (70.2%) are inside calls to verifyFunction.

If you drill into what verifyFunction is doing, all the time is spent in
recursive calls to visitMDNode. These calls are rooted in visitInstruction
calls to visitMDNode:
<a href="https://github.com/llvm/llvm-project/blob/master/llvm/lib/IR/Verifier.cpp#L4431">https://github.com/llvm/llvm-project/blob/master/llvm/lib/IR/Verifier.cpp#L4431</a>

visitMDNode in turn validates each of its operands. This is undesirable when
validating a function: location metadata points upwards, so validating one
location will ultimately validate the entire metadata graph rooted in the
compile unit. See the tree of calls in this screenshot:
<a href="https://reviews.llvm.org/file/data/u5ms43qqwl3aahxopjql/PHID-FILE-ysoomivlg3fixz52f4ny/visitmdnode-profile.png">https://reviews.llvm.org/file/data/u5ms43qqwl3aahxopjql/PHID-FILE-ysoomivlg3fixz52f4ny/visitmdnode-profile.png</a>

The code I linked was added in
<a href="http://github.com/llvm/llvm-project/commit/8dfe819bcd23">http://github.com/llvm/llvm-project/commit/8dfe819bcd23</a>, but I'm not sure when
this regressed. We used to ship clang with assertions enabled, so we saw these
non-linear assert compile time issues in the field as they arose. Now that we
are no longer watching carefully, it seems like these issues can slip in.

Should we try to establish the invariant that llvm::verifyFunction runs in
O(#instructions), or should we move all calls to verifyFunction to
EXPENSIVE_CHECKS?</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>