[llvm-bugs] [Bug 47147] New: saturating loops should exit early once the saturation condition is met

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Aug 12 15:18:14 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47147

            Bug ID: 47147
           Summary: saturating loops should exit early once the saturation
                    condition is met
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: richard-llvm at metafoo.co.uk
                CC: llvm-bugs at lists.llvm.org

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200812/5c907519/attachment.html>


More information about the llvm-bugs mailing list