<html>
    <head>
      <base href="https://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 --- - [LoopInterchange] Calls with side effects should prevent loop interchange."
   href="https://llvm.org/bugs/show_bug.cgi?id=30480">30480</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[LoopInterchange] Calls with side effects should prevent loop interchange.
          </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>normal
          </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>mcrosier@codeaurora.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Given the below test case:

void foo(unsigned a);
unsigned A[100][100];

void interchange_w_call() {
  for (int i = 0; i < 100; ++i)
    for(int j = 0; j < 100; ++j) {
      foo(A[j][i]);
      A[j][i] = i * j;
    }
}

The loop interchange pass will interchange this loop.  However, the interchange
will change the order of the values passed to foo().  If foo() has side
effects, I believe this optimization is legal.

Compile with debug output:
 clang loopinterchange.c -S -o /dev/null -O3 -mllvm -enable-loopinterchange
-mllvm -debug-only=loop-interchange

Calling populateWorklist on Func: interchange_w_call Loop: %for.cond1.preheader
Worklist size = 1
Processing LoopList of size = 2
Found 2 Loads and Stores to analyze
Found anti dependency between Src and Dst
 Src:  %0 = load i32, i32* %arrayidx6, align 4, !tbaa !1
 Dst:  store i32 %2, i32* %arrayidx6, align 4, !tbaa !1
Processing Inner Loop Id = 1 and OuterLoopId = 0
Checking if loops are tightly nested
Checking instructions in Loop header and Loop latch
Loops are perfectly nested
Loops are legal to interchange
Cost = -1
Calling Split Inner Loop
splitInnerLoopLatch done
Output of splitInnerLoopHeader InnerLoopHeaderSucc & InnerLoopHeader
splitInnerLoopHeader done
adjustLoopBranches called
Loops interchanged</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>