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: [email protected]
Reporter: [email protected]
CC: [email protected]
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._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs