<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 --- - Failure to remove trivial loop iterations"
   href="http://llvm.org/bugs/show_bug.cgi?id=20813">20813</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Failure to remove trivial loop iterations
          </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>Created <span class=""><a href="attachment.cgi?id=12963" name="attach_12963" title="C++ source code for example">attachment 12963</a> <a href="attachment.cgi?id=12963&action=edit" title="C++ source code for example">[details]</a></span>
C++ source code for example

Given a loop where some of the iterations are trivial, LLVM current fails to
change the iteration space to remove them.  Consider this example:
void test_cont_high_gt() {
  for(int i = 0; i < 20; i++) {
    if( i > 10 ) continue;
    counter++;
  }
}

In this example, iterations 10+ of this loop can simple be removed.  This would
leave a substaintially simpiler loop:
void test_cont_high_gt() {
  for(int i = 0; i < 11; i++) {
    counter++;
  }
}

The attached file has a number of variants of this example.  This does not
appear to be a pass ordering problem.  Running the IR through O3 repeatedly
does not improve the quality.

I suspect this particular pattern is simply a missing case from LoopSimplify. 
By inspecting the exit conditions of the loop in combination with the induction
variable, we should be able to rewrite the range of the induction variable to
shrink the iteration space.  

This example can also be viewed as a special case of loop splitting (i.e.
dividing the loop iteration space into two non-overlapping sections via two
loops) followed by dead loop deletion.  I doubt it is worth implementing the
more general optimization strategy (loop splitting) just to get this case.</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>