<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 --- - [LICM] Loop invariant terminator of loop header can be moved to preheader"
   href="http://llvm.org/bugs/show_bug.cgi?id=21763">21763</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[LICM] Loop invariant terminator of loop header can be moved to preheader
          </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>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>Loop Optimizer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>listmail@philipreames.com
          </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>Given a loop like this:
for(int i = 0; i < N; i++) {
  if(cond) return true;
}
return false;

We currently leave the branch instruction in the loop.  We do this because
there might have been control flow before the branch condition and if so, it
wouldn't be safe to lift the branch.  

However, there's an important case where we can actually lift this.  If the
loop has a preheader, we know that the instructions in the header will execute
exactly when the instructions in the preheader execute.  (The preheader
dominates the header and has a single successor which is the header.)  If the
loop invariant branch is terminating the loop header (and there are no
potentially faulting instructions in that basic block which aren't loop
invariant), we should be able to pull the branch into the loop preheader
(creating a new preheader in the process).  

Currently, we vectorize this loop and create an utter mess of useless IR.  I'm
not sure why, but loop unswitch does not seem to trigger on this loop within
the standard O3 pass ordering.  Invoking it individually does get this case,
but loop unswitching is more heavy weight than is needed here.  There's also an
advantage to be had by interweaving normal LICM and header-terminator-LICM.</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>