<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/72045>72045</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang cannot optimize fraction `(c * a / b)` when c is a power of 2 under the condition that other fraction `(a / d)` implies
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
k-arrows
</td>
</tr>
</table>
<pre>
Consider the following functions.
https://godbolt.org/z/KxdWKofjd
```cpp
int test2(int a) {
if (a / 5)
return 0;
else
return (2 * a / 9);
}
int test3(int a) {
if (a / 5)
return 0;
else
return (3 * a / 13);
}
int test4(int a) {
if (a / 5)
return 0;
else
return (4 * a / 17);
}
int test5(int a) {
if (a / 5)
return 0;
else
return (5 * a / 21);
}
int test6(int a) {
if (a / 5)
return 0;
else
return (6 * a / 25);
}
int test7(int a) {
if (a / 5)
return 0;
else
return (7 * a / 29);
}
int test8(int a) {
if (a / 5)
return 0;
else
return (8 * a / 33);
}
```
All of these functions can be optimized (to the function which returns zero), but Clang cannot optimize `test2`, `test4`, and `test8`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0lc9u4yAQxp9mfBk1woP_HnxIW_nSB9gzNiSmSyACvNnt06-Ik9bb3Uo5bCRLBjz--M0M_ixC0HurVAflI5TPmZjj5Hz3_UF4704hG5z81T05G7RUHuOkcOeMcSdt97ib7Ri1s2ED7BnYdorxGIBvgXqgfu_k4EzcOL8H6t-A-pef8tuL273KJRwqtlzj8bisaBsxqhAJqEljAdQi1I_LU0S9Q6BGIFCPJVB7XUf0Ks7eIgP-HqxMUH8FADWEQFtcRNokcn0F6ufL4A8Y_h9gvmLhK5ac3wBT3LMyxZqmvoGmvCdNuaKh_Aaa6o6NqtYw5Q0w9T1LU69pbjnDzT1pmhUN_-IQXz_1NdzWGHS75ClBfXgJjsLioNAdoz7oNyXTFtEt1nMJwtOkx-mCEPBNeZe2pScc5ohPRth9krEuvssgVGyxloqlwMu0uEyFldelBiq2yWTHZctbkakur9q2rnjDqmzqpFAlCVmyVpUll7kQjWiopLopiLUqz3RHjHie58QKXhXVhlcjL_kuL2qmWF0yKJg6CG02xvw4JHfMdAiz6mpiRZkZMSgTzm5MNKZMgCgZs-9S_MMw7wMUzOgQw4dC1NGobvxn4jsvlqKdU23GVbeGVLWK4WlSFkfUAQUe3Un51BfC2V49f3RW6rNInEREFyflPwsvkvIiqQ9Ho1XIZm-6T_8FHad52IzuANSnDC63h6N3r2qMQP25IAGoP9fkdwAAAP__UO_OOA">