<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 - Optimize exception_ptr, especially for common cases."
   href="https://bugs.llvm.org/show_bug.cgi?id=45547">45547</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Optimize exception_ptr, especially for common cases.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </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>All Bugs
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Right now the libc++ exception_ptr type is very expensive to use, even in the
cases where it is never or very rarely non-null. Given the intended usage, that
is likely to be the common case. This type will become even more important with
coroutines, and a poor implementation will handicap the performance of task
types, even when the compiler can prove that no exception will be thrown.

Specific improvements:
- Move optimization. Right now it is copy-only, while moves should be as cheap
as for unique_ptr.
- Swap optimization. Currently only the MSABI implementation has a specialized
std::swap. Using the default on intanium abi is very bad right now without move
optimizations, but even with them, it should generate better code if customized
than if not.
- Inline trivial operations for null cases, only calling out-of-line helpers
for non-null cases. This is especially important for the destructor and move
operations since currently the compiler is forced to emit an out of line call,
even when it can prove the pointer is null. This would also be useful for copy
operations.
- Comparison to nullptr shouldn't construct an exception_ptr that needs to be
destroyed. This may not matter if the prior bullet is done.

Example codegen that should all optimize away: <a href="https://godbolt.org/z/NaNKe5">https://godbolt.org/z/NaNKe5</a>

Related libstdc++ bug: <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90295">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90295</a></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>