<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - Missed optimization by O2? LTO generates faster code than O2 with all code visible"
   href="http://llvm.org/bugs/show_bug.cgi?id=21201">21201</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed optimization by O2? LTO generates faster code than O2 with all code visible
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </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>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>opt
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=13169" name="attach_13169" title="Example project that benchmarks tagged">attachment 13169</a> <a href="attachment.cgi?id=13169&action=edit" title="Example project that benchmarks tagged">[details]</a></span>
Example project that benchmarks tagged

I know this sounds like expected behaviour, but is it possible there's some
optimization opportunity that clang is missing @ -02/-O3 whereas it's caught by
LTO?

The benchmark is I build a vector of a type that wraps a boost::variant of 2
types.  I then iterate invoking a function on each element of the vector & time
the result.

-O2 -flto: vector with types in random-order:
TaggedDispatch.TaggedDispatch (457.022675 ms)

-O2 -flto: vector with types in-order:
TaggedDispatch.TaggedDispatch (100.611670 ms)

-O2: vector with types in random order:
TaggedDispatch.TaggedDispatch (652.344259 ms)

-O2: vector in-order:
TaggedDispatch.TaggedDispatch (326.946609 ms)

-O3: vector with types in random order:
TaggedDispatch.TaggedDispatch (647.796656 ms)

-O3: vector in-order:
TaggedDispatch.TaggedDispatch (330.778245 ms)

We can see that somehow -flto manages to squeeze out quite a bit of performance
which is unexpected.  There's no difference between O2 & O3.

Numbers generated with Xcode's clang on OSX 10.10.  The version of boost
appeared to not matter (numbers consistent between boost 1.51 & boost 1.55).

You may have to edit the makefile to point to your boost if it's not in your
system path.</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>