[llvm-bugs] [Bug 44156] New: Loop layering based on a monotonic condition between two loop indvars

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Nov 26 23:54:15 PST 2019


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

            Bug ID: 44156
           Summary: Loop layering based on a monotonic condition between
                    two loop indvars
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: lebedev.ri at gmail.com
                CC: llvm-bugs at lists.llvm.org

void init(int colIn, int colOut);
void sink(int colIn, int colOut);

void bad(int inputWidth, int outWidth) {
    for(int colIn = 0, colOut = 0; colOut < outWidth; ++colIn, ++colOut) {
        if(colIn == inputWidth) {
            init(colIn, colOut);
            colIn = 0;
        }

        sink(colIn, colOut);
    }
}

Every iteration of innermost branch we have a conditional branch.
But we can avoid it, by having two loops, with now-innermost
running for precomputed number of iterations with no such branching:

#include <algorithm>

void init(int colIn, int colOut);
void sink(int colIn, int colOut);

void good(int inputWidth, int outWidth) {
    for(int colOut = 0, colIn = 0; colOut < outWidth; ) {
        if(colIn == inputWidth) {
            init(colIn, colOut);
            colIn = 0;
        }

        int outColForNextInRow = outWidth - colIn;

        for( ; colOut < std::min(outWidth, outColForNextInRow)
             ; ++colIn, ++colOut)
            sink(colIn, colOut);
    }
}


https://godbolt.org/z/MMMaKb

-- 
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/20191127/071e8b56/attachment.html>


More information about the llvm-bugs mailing list