<html>
    <head>
      <base href="http://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 --- - Loop reroller fails to reroll loop with variable upper bound on 64-bit targets"
   href="http://llvm.org/bugs/show_bug.cgi?id=18374">18374</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Loop reroller fails to reroll loop with variable upper bound on 64-bit targets
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </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>NEW
          </td>
        </tr>

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

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

        <tr>
          <th>Component</th>
          <td>opt
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=11813" name="attach_11813" title="test.c">attachment 11813</a> <a href="attachment.cgi?id=11813&action=edit" title="test.c">[details]</a></span>
test.c

Given this loop:

$ cat test.c
void foo(int *A, int *B, int n) {
  for (int i = 0; i < n; i+=4) {
    A[i+0] = B[i+0] * 4;
    A[i+1] = B[i+1] * 4;
    A[i+2] = B[i+2] * 4;
    A[i+3] = B[i+3] * 4;
  }
}

The loop reroller fails to reroll the loop on the 64-bit targets I tested
(x86_64 and AArch64).

  $ clang -target x86_64-none-linux test.c -S -o- -O1 -emit-llvm -o test.ll
  $ opt -loop-reroll -S -debug-only=loop-reroll -stats

It works correctly on 32-bit targets (tested i386 and armv7).

Looking at the bitcode, I suspect the problem is that the induction variable is
extended to 64-bits, but the loop bound remains 32-bits. The induction variable
is truncated inside the loop body to 32-bits. I think this makes SCEV unable to
compute the number of times the backedge is taken.

If I change the "int n" to a "long n" the loop is successfully rerolled.</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>