<html>
    <head>
      <base href="https://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 --- - Function not inlined when it should probably be" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D23818&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=y9kvds9655ZngFZLPs0ODnzd0SY90Ly12murPSzSa38&s=h8j5Ktic7IHSO8XYYDqZi2ELQAcI5TV6eMMRQihWB9k&e=">23818</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Function not inlined when it should probably be
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

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

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </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>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>ldionne.2@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=14462" name="attach_14462" title="Minimal working example">attachment 14462</a> <a href="attachment.cgi?id=14462&action=edit" title="Minimal working example">[details]</a></span>
Minimal working example

Hi,

I have run into a situation[1] where a function should probably be inlined 
but it isn't, resulting in very suboptimal code to be generated. The gist 
of the problem goes as follows:

    auto f() {
        return /* 
            some very large structure which is quite complicated to 
            construct, but which can also be constructed as a constant
            expression. In other words, the expression in the return 
            statement, while being complex, is only composed of constant
            expressions.
         */;
    }

    int main() {
        // In the generated assembly, the code for `f` is generated, which
        // is O.K. because `f` has external linkage. That assembly is pretty  
        // bad, since it has to pass the huge structure returned by f by 
        // value, which spills.
        //
        // However, this call right here to `f()` is not optimized away. 
        // In other words, even though the definition of `f` is visible
        // to the optimizer, `f` is called, resulting in the awful code
        // to be executed. 
        //
        // If `f` is marked as inline, the call is optimized to nothing
        // (and the code of f is not even generated).
        f();
    }


A minimal working example with comments is attached. I realize this is 
a quality of implementation issue more than an actual bug, but I think 
my actual use case[1] justifies at least looking into the problem.


Regards,
Louis

[1]: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__article.gmane.org_gmane.comp.lib.boost.devel_261035&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=y9kvds9655ZngFZLPs0ODnzd0SY90Ly12murPSzSa38&s=WD_brkLjROOt8pcbnWGxERabaC4DWnnlZdKiGBFDGE4&e=">http://article.gmane.org/gmane.comp.lib.boost.devel/261035</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>