<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 - [LSR] Bad code generation from LSR"
   href="https://bugs.llvm.org/show_bug.cgi?id=36854">36854</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[LSR] Bad code generation from LSR
          </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>Loop Optimizer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>junbuml@codeaurora.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>For the C code below, the transformation done by LSR cause bad code generation
on AArch64. 

int isTrue();

void test(int M, int *P, int *P2, int *P3, int *P4) {
  int t = 0;
  for (int k = 1; k <= M; ++k) {
    P[k] = P2[k-1] + P[k-1];
    P3[k] = P2[k-1] + P3[k-1];
    if (isTrue()) {
      P4[k] = P[k] + P2[k];
    }
  }
}

# Current code generation  -----------------------------------------

.LBB0_2:
        ldr     w8, [x19]
        ldur    w9, [x20, #-4]
        add     w8, w9, w8
        str     w8, [x20]
        ldr     w8, [x19]
        ldur    w9, [x21, #-4]
        add     w8, w9, w8
        str     w8, [x21]
        bl      isTrue
        cbz     w0, .LBB0_4
// %bb.3:                               // %if.then
        ldr     w8, [x20]
        ldr     w9, [x19, #4]
        add     w8, w9, w8
        str     w8, [x23]
.LBB0_4:                                // %for.inc
                                        //   in Loop: Header=BB0_2 Depth=1
        subs    x22, x22, #1            // =1
        add     x20, x20, #4            // =4
        add     x21, x21, #4            // =4
        add     x23, x23, #4            // =4
        add     x19, x19, #4            // =4
        b.ne    .LBB0_2


#Code when skipping LSR --------------------------------------------------

.LBB0_2:                                // %for.body
                                        // =>This Inner Loop Header: Depth=1
        lsl     x25, x24, #2
        sub     x8, x25, #4             // =4
        ldr     w9, [x21, x8]
        ldr     w10, [x22, x8]
        add     w9, w10, w9
        str     w9, [x22, x25]
        ldr     w9, [x21, x8]
        ldr     w8, [x20, x8]
        add     w8, w8, w9
        str     w8, [x20, x25]
        bl      isTrue
        cbz     w0, .LBB0_4
// %bb.3:                               // %if.then
                                        //   in Loop: Header=BB0_2 Depth=1
        ldr     w8, [x22, x25]
        ldr     w9, [x21, x25]
        add     w8, w9, w8
        str     w8, [x19, x25]
.LBB0_4:                                // %for.inc
                                        //   in Loop: Header=BB0_2 Depth=1
        add     x24, x24, #1            // =1
        cmp     x24, x23
        b.ne    .LBB0_2</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>