<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - saturating loops should exit early once the saturation condition is met"
   href="https://bugs.llvm.org/show_bug.cgi?id=47147">47147</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>saturating loops should exit early once the saturation condition is met
          </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>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </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>richard-llvm@metafoo.co.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Example:

bool f(int *p, int *q) {
    bool b = false;
    for (; p != q; ++p)
        if (*p <= 0) b = true;
    return b;
}

... should probably be optimized to:

bool f(int *p, int *q) {
    bool b = false;
    for (; p != q; ++p)
        if (*p <= 0) return true;
    return false;
}

(that is, exit early once the loop has reached a saturation condition).
Currently neither LLVM nor GCC (nor ICC nor MSVC) performs this optimization.

Aside: the above loop is also not unrolled. But if it's rewritten as

    for (int i = 0; i != q - p; ++i)
        if (p[i] <= 0) b = true;

... then it gets unrolled 4x.</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>