<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 reduce loop w/known exit conditions (pass ordering?)"
   href="http://llvm.org/bugs/show_bug.cgi?id=20812">20812</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Failure to reduce loop w/known exit conditions (pass ordering?)
          </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=12961" name="attach_12961" title="C++ source code for example">attachment 12961</a> <a href="attachment.cgi?id=12961&action=edit" title="C++ source code for example">[details]</a></span>
C++ source code for example

LLVM O3 will currently convert this loop into a single increment of "counter":
void test_return_high_gt() {
  for(int i = 0; i < 20; i++) {
    if( i > 10 ) return;
    counter++;
  }
}

But will not perform the same optimization on this loop:
int test_return_value_high_gt() {
  for(int i = 0; i < 20; i++) {
    if( i > 10 ) return 0;
    counter++;
  }
  return 1;
}

I have not analyzed this extensively, but I suspect this is a pass ordering
problem.  If I run the IR generated by Clang for the second example through
"opt -O3" twice, I get the exact same IR as in the first example.  

I've attached both the cpp example and the LL file generated by clang 3.4 w/O3.
 I used a recent TOT opt version for the pass ordering investigation.</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>