<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 --- - don't unroll a loop that has no hope for improvement"
   href="https://llvm.org/bugs/show_bug.cgi?id=26532">26532</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>don't unroll a loop that has no hope for improvement
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Loop Optimizer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I'm not sure where this should be solved, but the "unroll-runtime" pass should
be reined in / less aggressive.

I was looking at the example in <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - 30% performance deficiency vs GCC because of excessive vectorization on -march=slm"
   href="show_bug.cgi?id=25108">bug 25108</a> and wondered what happened with
simpler cases:

int foo(int x, int n) {
  for (int i=0; i<n; i++)
    x = x * x;
  return x;
}

With:
$ ./clang -v
clang version 3.9.0 (trunk 260122)
Target: x86_64-apple-darwin15.3.0

$ ./clang -O2 25108.c -S -emit-llvm -o -

This gets unrolled 8x + prologue code. The net effect is that code which should
be simple like this (-Os or gcc 5.3 with -O2 is similar):
00    testl    %esi, %esi
02    jle    0xb
04    imull    %edi, %edi
07    decl    %esi
09    jne    0x4
0b    movl    %edi, %eax
0d    retq

...is bloated out to 64 bytes with almost no chance that this could be better
for performance on any recent x86:
00    testl    %esi, %esi
02    jle    0x3d
04    leal    -0x1(%rsi), %ecx
07    xorl    %eax, %eax
09    movl    %esi, %edx
0b    andl    $0x7, %edx
0e    je    0x19
10    imull    %edi, %edi
13    incl    %eax
15    cmpl    %eax, %edx
17    jne    0x10
19    cmpl    $0x7, %ecx
1c    jb    0x3d
1e    subl    %eax, %esi
20    imull    %edi, %edi
23    imull    %edi, %edi
26    imull    %edi, %edi
29    imull    %edi, %edi
2c    imull    %edi, %edi
2f    imull    %edi, %edi
32    imull    %edi, %edi
35    imull    %edi, %edi
38    addl    $-0x8, %esi
3b    jne    0x20
3d    movl    %edi, %eax
3f    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>