<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 - ThinLTO doesn't know about constant return values"
   href="https://bugs.llvm.org/show_bug.cgi?id=33604">33604</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ThinLTO doesn't know about constant return values
          </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>Severity</th>
          <td>enhancement
          </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>davide@freebsd.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>charles.saternos@gmail.com, davidxl@google.com, joker.eph@gmail.com, llvm-bugs@lists.llvm.org, tejohnson@google.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>As Charles, our GSoC student working on ThinLTO was looking for opportunities
to improve ThinLTO, here's something that came to my mind.

I'm not sure whether we want to go in this direction, but it's a start.

$ cat a.c
__attribute__((noinline))
int patatino(void) {
  return 47;
}

$ cat b.c
extern int patatino(void);

int main(void) {
  return patatino();
}

$ ../clang a.c b.c -flto -fuse-ld=lld -Wl,-save-temps -o patatino-lto
$ objdump -d patatino-lto

[...]

0000000000201190 <main>:
  201190:       55                      push   %rbp
  201191:       48 89 e5                mov    %rsp,%rbp
  201194:       48 83 ec 10             sub    $0x10,%rsp
  201198:       c7 45 fc 00 00 00 00    movl   $0x0,-0x4(%rbp)
  20119f:       e8 dc ff ff ff          callq  201180 <patatino>
  2011a4:       b8 2f 00 00 00          mov    $0x2f,%eax
  2011a9:       48 83 c4 10             add    $0x10,%rsp
  2011ad:       5d                      pop    %rbp
  2011ae:       c3                      retq

With ThinLTO:

$ ../clang a.c b.c -flto=thin -fuse-ld=lld -Wl,-save-temps -o patatino-thin
$ $ objdump -d ./patatino-thin

[...]

0000000000201190 <main>:
  201190:       55                      push   %rbp
  201191:       48 89 e5                mov    %rsp,%rbp
  201194:       48 83 ec 10             sub    $0x10,%rsp
  201198:       c7 45 fc 00 00 00 00    movl   $0x0,-0x4(%rbp)
  20119f:       e8 dc ff ff ff          callq  201180 <patatino>
  2011a4:       48 83 c4 10             add    $0x10,%rsp
  2011a8:       5d                      pop    %rbp
  2011a9:       c3                      retq</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>