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: unassignedb...@nondot.org
Reporter: lebedev...@gmail.com
CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs