<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 3, 2015 at 7:56 AM, Tobias Grosser <span dir="ltr"><<a href="mailto:tobias@grosser.es" target="_blank">tobias@grosser.es</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On 06/03/2015 09:58 AM, David Majnemer wrote:<br>
</span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">
<br>
<br>
On Tue, Jun 2, 2015 at 11:31 PM, Tobias Grosser <<a href="mailto:tobias@grosser.es" target="_blank">tobias@grosser.es</a><br></span><span class="">
<mailto:<a href="mailto:tobias@grosser.es" target="_blank">tobias@grosser.es</a>>> wrote:<br>
<br>
    Author: grosser<br>
    Date: Wed Jun  3 01:31:30 2015<br>
    New Revision: 238905<br>
<br>
    URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D238905-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=v1NmYvDYuV_-0nT9JGlwfVij3WqgK6AY67cufMQBMN8&s=snIoRJi4vamq1_cksP4iVaNvaeMVcs1vhLvbVD_v4_g&e=" target="_blank">http://llvm.org/viewvc/llvm-project?rev=238905&view=rev</a><br>
    Log:<br>
    Translate power-of-two floor-division into ashr<br>
<br>
    Power-of-two floor divisions can be translated into an arithmetic shift<br>
    operation. This allows us to replace a complex lowering that<br>
    requires division<br>
    operations:<br>
<br>
<br>
This only holds if the numerator is non-negative.  -1/INT_MIN should<br>
give 0 but calculating it with a right-shift would give -1.<br>
</span></blockquote>
<br>
Your example -1/INT_MIN is uses negative operands in both the numerator and the denominator. This it indeed failed with my code. However, the case of negative numerators with positive denominators should be fine, as we are translating here a division with rounding towards -inf, not rounding towards zero as the sdiv instruction in LLVM uses. Or did I miss something here.<br></blockquote><div><br></div><div>Here is an example using a negative numerator and a positive denominator:</div><div>%r = sdiv i32 2550202368, 1073741824 => -1</div><div><br></div><div>Here is what shifting produces:</div><div>%r = ashr i32 2550202368, 30 => -2</div>







<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
I know exclude negative values 'b' from this optimization and also fixed the dyn_cast issue in 238927.<br></blockquote><div><br></div><div>Thanks!</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Best,<br>
Tobias<br>
</blockquote></div><br></div></div>