<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 not able to reroll when the array base address is a derivative of the loop induction variable"
   href="http://llvm.org/bugs/show_bug.cgi?id=18646">18646</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Loop reroller not able to reroll when the array base address is a derivative of the loop induction variable
          </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>chrisj@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=11960" name="attach_11960" title="test.c">attachment 11960</a> <a href="attachment.cgi?id=11960&action=edit" title="test.c">[details]</a></span>
test.c

The loop reroller is not able to reroll loops of the form where the array base
address is a derivative of the loop induction variable.

$ cat test.c

void foo(int *Arr, int n) {
  for (int i = 0; i < n; i += 3) {
     Arr[0]=0;
     Arr[1]=0;
     Arr[2]=0;
     Arr+=3;
   }
}


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

This is probably because as the array accesses are not a function of the loop
induction variable, which is the loop body form the reroller pass requires.

$ cat test.ll
..
..
for.body:                                         ; preds = %entry, %for.body
  %i.09 = phi i32 [ %add, %for.body ], [ 0, %entry ]
  %Arr.addr.08 = phi i32* [ %add.ptr, %for.body ], [ %Arr, %entry ]
  store i32 0, i32* %Arr.addr.08, align 4, !tbaa !1
..
..


The following pattern is successfully rerolled as it satisfies the requirement,

void foo(int *Arr, int n) {
  for (int i = 0; i < n; i += 3) {
     Arr[i]=0;
     Arr[i+1]=0;
     Arr[i+2]=0;
   }
}</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>