<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 - Bad inlining decision when caller puts on stack bunch of unused in callee data (boost::variant visitation)"
   href="https://bugs.llvm.org/show_bug.cgi?id=41491">41491</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Bad inlining decision when caller puts on stack bunch of unused in callee data (boost::variant visitation)
          </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>All
          </td>
        </tr>

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

        <tr>
          <th>Keywords</th>
          <td>code-quality
          </td>
        </tr>

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

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

        <tr>
          <th>Component</th>
          <td>Interprocedural Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>nok.raven@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Blocks</th>
          <td>4931
          </td>
        </tr></table>
      <p>
        <div>
        <pre>boost::variant visitation recursively wraps visitor reference about 3 times.
LLVM decides to not inline even relatively-small switches, leaving switch in
one function and all visitor wrapping in another. Because of that it cannot
optimize-out those wrappers and produces bunch of store/loads.

I don't know whether GCC is more clever or aggressive, but it will inline the
switch even a huge one. <a href="https://godbolt.org/z/R6NpPa">https://godbolt.org/z/R6NpPa</a>


// Removes switch bloat due to std::abort, will be part of Boost 1.71
#define BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP
namespace boost { namespace detail { namespace variant {
template <typename T> T forced_return() { __builtin_unreachable(); }
}}}

#include <boost/variant.hpp>

struct A {}; struct B {}; struct C {};
struct D {}; struct E {}; struct F {};
struct G {}; struct H {}; struct J {};

template <typename T> void f(T);

struct Visitor
{
    template <typename T> void operator()(T v) const { f(v); }
};

void foo(boost::variant<A, B, C, D, E, F, G, H, J> v)
{
    boost::apply_visitor(Visitor{}, v);
}</pre>
        </div>
      </p>

        <div id="referenced">
          <hr style="border: 1px dashed #969696">
          <b>Referenced Bugs:</b>
          <ul>
              <li>
                [<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [meta] Improve inlining effectiveness"
   href="https://bugs.llvm.org/show_bug.cgi?id=4931">Bug 4931</a>] [meta] Improve inlining effectiveness
              </li>
          </ul>
        </div>
        <br>

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

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