<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_ASSIGNED "
   title="ASSIGNED --- - OptimizeLEAPass is too slow"
   href="https://llvm.org/bugs/show_bug.cgi?id=25843">25843</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>OptimizeLEAPass is too slow
          </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>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>ASSIGNED
          </td>
        </tr>

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

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

        <tr>
          <th>Component</th>
          <td>Backend: X86
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>a.bataev@hotmail.com
          </td>
        </tr>

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, nadav256@gmail.com, qcolombet@apple.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>OptimizeLEAPass added in r254712 and triggered by -Os on X86 platforms is
unacceptably slow. Its algorithm complexity is at least
O(MBB * ACCESS * LEA)
where MBB is the number of machine basic blocks in a function,
ACCESS is the number of load/stores in a basic block,
LEA is the number of lea instructions in a basic block.

The last two numbers can easily grow to thousands in real-life code (especially
in auto-generated functions), exploding the compile time.

Please investigate optimization improvements, or add a bound to avoid
triggering this pass. To reproduce:

$ cat a.py
import sys

def foo(n):
  print '#include <unordered_map>'
  print 'std::unordered_map<int, int> m;'
  print 'void foo() {'
  for i in range(n):
    print '  m[%d] = %d;' % (i, i + 100);
  print '}'

if __name__ == '__main__':
  foo(int(sys.argv[1]))

$ python a.py 200 > a.cc ; time ./bin/clang++ -std=c++11 -c a.cc -o a.o -Os

real    0m0.892s
user    0m0.852s
sys    0m0.040s
$ python a.py 400 > a.cc ; time ./bin/clang++ -std=c++11 -c a.cc -o a.o -Os

real    0m3.438s
user    0m3.412s
sys    0m0.030s
$ python a.py 800 > a.cc ; time ./bin/clang++ -std=c++11 -c a.cc -o a.o -Os

real    0m23.815s
user    0m23.709s
sys    0m0.116s</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>