<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 - trivial static loop is not eliminated with -Os"
   href="https://bugs.llvm.org/show_bug.cgi?id=40040">40040</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>trivial static loop is not eliminated with -Os
          </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>Common Code Generator Code
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>void foo(int* a)
{
        for (int i = 0; i < 8; ++i)
                a[i] = 1;
}

$ clang -Os -march=haswell

        xor     eax, eax
        vbroadcastss    ymm0, dword ptr [rip + .LCPI0_0] # ymm0 =
[1,1,1,1,1,1,1,1]
        mov     ecx, 8
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
        vmovups ymmword ptr [rdi + 4*rax], ymm0
        add     rax, 8
        cmp     rax, rcx
        jne     .LBB0_1

<a href="https://godbolt.org/z/Q2Se1r">https://godbolt.org/z/Q2Se1r</a>

It also happens with -O2 -fno-unroll-loops and -Os -funroll-loops.
You can also change the loop body, e.g. ++a[i].</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>