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

            Bug ID: 43892
           Summary: Two-loop-deep loop peeling? ("loop scalar remainder
                    splitting")
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

This is indeed similar to scalarization of loop remainer.
Let's suppose we have a loop like: (can be written with a `break;` too)

void sink();

#define N 3

void bad(int width) {
    for(int col = 0; col < width; col += N) {
        int colsToRemaining = width - col;
        int colsToFill = std::min(colsToRemaining, N);        

        for(int i = 0; i < colsToFill; ++i) { 
            // can't unroll/vectorize loop,
            // variable ([1,N)) trip count
            sink();
        }
    }
}

That std::min() conditional trip count is pretty unfortunate,
since in majority of cases colsToFill will be N.
It would be great to split the loop into something like

void good(int width) {
    for(int col = 0; col < width; col += N) {
        int colsToRemaining = width - col;

        if(colsToRemaining >= N) {
            for(int i = 0; i < N; ++i) // can unroll
                sink(); // always runs N times
        } else {
            for(int i = 0; i < colsToRemaining; ++i) { 
                // can't unroll/vectorize loop,
                // variable ([1,N)) trip count
                sink();
            }
        }
    }
}

That allows to unroll the first inner loop with constant trip count,
and may help with vectorization.

Should something like this be performed?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to