<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Common code hoisting"
href="https://bugs.llvm.org/show_bug.cgi?id=52541">52541</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Common code hoisting
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>llvm@rifkin.dev
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>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();
}
}
}
<a href="https://godbolt.org/z/qjjMYWb8o">https://godbolt.org/z/qjjMYWb8o</a>
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);
}
}
}
<a href="https://godbolt.org/z/vTYj75cx6">https://godbolt.org/z/vTYj75cx6</a>
It seems there is room for improvement and generalization in this
transformation.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>