<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/59201>59201</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimizations around OR, DIV and checking ZF
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Kaznov
</td>
</tr>
</table>
<pre>
```c
uint64_t optimized_mod(uint64_t a, uint64_t b) {
if ((a|b) >> 32 == 0)
return (uint32_t)a % (uint32_t)b;
else
return a % b;
}
```
Here, for Intel architectures (and default code generation) an optimization triggers for modulo `a%b`, that tries to perform exactly the check that the function does. However, the effect in generated code is at least undesirable:
https://godbolt.org/z/oq5vojoYq
There is an unnecessary `test` and a duplicated `je` generated.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxdUstu2zAQ_BrqsqhBkZZkHXRI4gYJiqJAURRoLwElriW6NOmQlNPk67uSH3EjrETua2Z3oNbr14aV_Ggd42vGb0bjUrl8SuD3yezMG-qnnddMrC4JxcQdXLyWiRpYdXvsBnrMBqicTLHq7piWn8lACrqtyYBT9L2BnoBpDA5ONFI8JapQ5BcfYi2TV1RoI_6HcwY6tr4Xs2p9upzXPbnz9wEDTkttfIBHl9CCCt1gEnYEhnEaQTkNGjdqtAk6rxF6dBhUMt5NGyp31msOQQqm7zHEGZL0G60HIiXpinYiJ7I0qDTVEX7ysMdApTvAv6pL9pWyCN2A3Z9THbmb0XUzuPYYF_DgX_CA4QiFgJsNjQvGnSdDfRzURCAAiyomGJ3GaIJqLTJ5cy3BkNI-TjFxT9Z73XqbFj705L3R65-Lg9_6X8_XTT8GEm4mcATtsMMYVXidNk0YEx0w6aZAj3trunkmCm5xylzGXGTY5GVZy1VZVDLTjdS1rFWWTLLYfDUxUtu1usQXPK0C375P268ff840s1zG9fD7HrIx2ObDTiYNY7vo_I4caw_n49M--C1JRy5RjRjpUtSC59nQtEJxpbDKtSyqlSgrvep0rQpZ5aS34plVLf2DDStumRAOX2CGoDsr1plpBBciz0WRL0Ut5UJw3rWyVMWSqxVyzpYcd8rYxTTHJHYWmnmkduwjJa2JKb4nVYymd4gzHeGrMQ0-NF_Um_OHbGZu5sn_AZDIMAw">