[llvm-bugs] [Bug 52541] New: Common code hoisting
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Nov 17 20:35:32 PST 2021
https://bugs.llvm.org/show_bug.cgi?id=52541
Bug ID: 52541
Summary: Common code hoisting
Product: libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: llvm at rifkin.dev
CC: llvm-bugs at lists.llvm.org
The common call to foo() in this below code is hoisted above the if-else.
void A(int x) {
if(x < 0) { // arbitrary condition...
foo();
bar();
} else {
foo();
baz();
}
}
This transformation is missed in the following code:
void B(int x) {
if(x < 0) { // arbitrary condition...
foo();
bar();
} else if(x % 2 == 0) { // arbitrary condition...
foo();
baz();
} else {
foo();
boz();
}
}
Which is only transformed to
void B(int x) {
if(x < 0) { // arbitrary condition...
foo();
bar();
} else {
foo();
if(x % 2 == 0) { // arbitrary condition...
baz();
} else {
boz();
}
}
}
https://godbolt.org/z/qjjMYWb8o
This is also missed on switches.
This isn't just missed on function calls, it is missed with arithmetic as well:
void B(int x, int y) {
if(x < 0) { // arbitrary condition...
foo(x / y);
} else if(x % 2 == 0) { // arbitrary condition...
bar(x / y);
} else {
baz(x / y);
}
}
Transforms to:
void B(int x, int y) {
if(x < 0) { // arbitrary condition...
int v = x / y;
foo(v);
} else {
int v = x / y;
if(x % 2 == 0) { // arbitrary condition...
bar(v);
} else {
baz(v);
}
}
}
https://godbolt.org/z/vTYj75cx6
It seems there is room for improvement and generalization in this
transformation.
--
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/20211118/e0b2a36d/attachment-0001.html>
More information about the llvm-bugs
mailing list