<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 - Sub-optimal placement of loop exit blocks"
   href="https://bugs.llvm.org/show_bug.cgi?id=51185">51185</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Sub-optimal placement of loop exit blocks
          </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>Windows NT
          </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>momchil.velikov@arm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=25057" name="attach_25057" title="test case">attachment 25057</a> <a href="attachment.cgi?id=25057&action=edit" title="test case">[details]</a></span>
test case

In the attached test case there's is a (fully unrolled) loop roughly of the
following form

    for ... {
       if (cond) {
          stuff();
          break;
       }
       more_stuff();
    }

when compiled for AArch64 with `llc store.ll`, the output looks like:

// iteration 0
        cmp     w11, w12
        b.ne    .LBB0_2

        mov     x11, xzr
        b       .LBB0_14
.LBB0_2:
        ...

// iteration 1
        cmp     w17, w12
        b.ne    .LBB0_6

        add     w10, w10, #1
        mov     w11, #1    
        b       .LBB0_14
.LBB0_6:
        ...

// iteration 2
        cmp     w15, w12
        b.ne    .LBB0_10

        add     w10, w10, #2
        mov     w11, #2
        b       .LBB0_14
.LBB0_10:
        ...

// iteration 3
        cmp     w16, w12
        b.ne    .LBB0_15

        add     w10, w10, #3
        mov     w11, #3
        // fallthrough
.LBB0_14:
        // iterations 0, 1, 2, 3 early exit
        ...

i.e. the exit blocks are interspersed with "proper" body blocks and the 
execution constantly jumps over them. In contrast, GCC's output looks like:

// iteration 0
        ...
        cmp     w6, w0
        beq     .L19
        ...

// iteration 1
        ...
        cmp     w2, w6
        beq     .L20
        ...  

// iteration 2
        ...
        cmp     w6, w4
        beq     .L22
        ...
// iteration 3
        ...
        cmp     w2, w6
        beq     .L23


i.e. exit blocks an entirely stashed away and loop iterations are executed
essentially like straight line code.</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>