<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 --- - Performance regression with LTO after gold plugin change in r217458"
   href="http://llvm.org/bugs/show_bug.cgi?id=20974">20974</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Performance regression with LTO after gold plugin change in r217458
          </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>Windows NT
          </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>gold-plugin
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>avolkov.intel@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu, rafael.espindola@gmail.com, zinovy.nis@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>After change in r217458 in gold plugin there is a performance regression with
LTO due to symbol do not internalized.

$ cat a.c                                                                      
                                                                               
    extern int x;                                                              
                                                                               
                                                                               
                                                                               
                                                                void init_x()  
                                                                               
                                                                               
              {                                                                
                                                                               
                                              x = 7;                           
                                                                               
                                                                          }

$ cat b.c
#include <stdlib.h>
void init_x();
int x;

int main()
{
  x = 0;
  init_x();
  return rand() % x;
}

On x86 Sandy Bridge processor running
clang -Ofast -flto b.c a.c

Before change here we have optimized remainder calculation:
00000000004005b0 <main>:
  4005b0:       50                      push   %rax
  4005b1:       e8 da fe ff ff          callq  400490 <rand@plt>
  4005b6:       48 98                   cltq
  4005b8:       48 69 c8 93 24 49 92    imul   $0xffffffff92492493,%rax,%rcx
  4005bf:       48 c1 e9 20             shr    $0x20,%rcx
  4005c3:       89 c2                   mov    %eax,%edx
  4005c5:       01 ca                   add    %ecx,%edx
  4005c7:       89 d1                   mov    %edx,%ecx
  4005c9:       c1 e9 1f                shr    $0x1f,%ecx
  4005cc:       c1 fa 02                sar    $0x2,%edx
  4005cf:       01 ca                   add    %ecx,%edx
  4005d1:       6b ca 07                imul   $0x7,%edx,%ecx
  4005d4:       29 c8                   sub    %ecx,%eax
  4005d6:       5a                      pop    %rdx
  4005d7:       c3                      retq

After change remainder calculated through div with 2x drop in performance:
00000000004005b0 <main>:
  4005b0:       50                      push   %rax
  4005b1:       c7 05 c1 13 00 00 07    movl   $0x7,0x13c1(%rip)        #
40197c <x>
  4005b8:       00 00 00
  4005bb:       e8 d0 fe ff ff          callq  400490 <rand@plt>
  4005c0:       99                      cltd
  4005c1:       f7 3d b5 13 00 00       idivl  0x13b5(%rip)        # 40197c <x>
  4005c7:       89 d0                   mov    %edx,%eax
  4005c9:       5a                      pop    %rdx
  4005ca:       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>