<div dir="ltr">Thanks Nuno! <div><br></div><div>The first case is pretty rare. If (0 - a) does not unsigned overflow, then a must be 0. Right? <div><br></div><div>The second case is worth handling. I'll send a patch soon. </div>
<div><br></div><div>Jingyue</div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jun 25, 2014 at 2:00 PM, Nuno Lopes <span dir="ltr"><<a href="mailto:nunoplopes@sapo.pt" target="_blank">nunoplopes@sapo.pt</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You're right; there's a bug.<br>
<br>
I proved, however, the correctness of two cases:<br>
1) X - (0 -nuw A) -> X +nuw nsw A<br>
2) X -nsw (0 -nsw A) -> X +nsw A<br>
<br>
Not sure if the complexity of implementing this is worth the trouble, though.<br>
<br>
Nuno<br>
<br>
----- Original Message ----- From: "Jingyue Wu" <<a href="mailto:jingyue@google.com" target="_blank">jingyue@google.com</a>><br>
Sent: Wednesday, June 25, 2014 5:48 AM<br>
Subject: [LLVMdev] Question Regarding Sign-Overflow<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I have doubts on the following transformation in InstCombineAddSub.cpp. Is<br>
it always safe to preserve NSW/NUW in this case?<br>
<br>
  // If this is a 'B = x-(-A)', change to B = x+A.  This preserves NSW/NUW.<br>
  if (Value *V = dyn_castNegVal(Op1)) {<br>
    BinaryOperator *Res = BinaryOperator::CreateAdd(Op0, V);<br>
    Res->setHasNoSignedWrap(I.<u></u>hasNoSignedWrap());<br>
    Res->setHasNoUnsignedWrap(I.<u></u>hasNoUnsignedWrap());<br>
    return Res;<br>
  }<br>
<br>
Suppose A = x = (i4 -8) (the minimum signed integer of i4). The first<br>
minus in x - (-A) does not sign-overflow, but x + A sign-overflows.<br>
<br>
Thanks,<br>
Jingyue <br>
</blockquote>
<br>
</div></div></blockquote></div><br></div>