[llvm-bugs] [Bug 34364] New: 'hoisting conditional out of loop' missed optimization opportunity
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Aug 29 13:02:43 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=34364
Bug ID: 34364
Summary: 'hoisting conditional out of loop' missed optimization
opportunity
Product: new-bugs
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: lebedev.ri at gmail.com
CC: llvm-bugs at lists.llvm.org
Old code:
int get();
void func(int y, int width, int* img) {
__builtin_assume(width > 4);
int vpred[2][2] = {{0, 0}, {0, 0}};
int hpred[2];
for (int x = 0; x < width; x++) {
int diff = get();
if (x < 2)
hpred[x] = vpred[y & 1][x] += diff;
else
hpred[x & 1] += diff;
img[x] = hpred[x & 1];
}
}
Equivalent code without inner if:
int get();
void func(int y, int width, int* img) {
__builtin_assume(width > 4);
int vpred[2][2] = {{0, 0}, {0, 0}};
int hpred[2];
int x;
int diff;
x = 0;
diff = get();
hpred[x] = vpred[y & 1][x] += diff;
img[x] = hpred[x & 1];
x = 1;
diff = get();
hpred[x] = vpred[y & 1][x] += diff;
img[x] = hpred[x & 1];
for (; x < width; x++) {
diff = get();
hpred[x & 1] += diff;
img[x] = hpred[x & 1];
}
}
According to godbolt, clang trunk can not do that: https://godbolt.org/g/cS6RD5
--
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/20170829/f12efb50/attachment.html>
More information about the llvm-bugs
mailing list