<div dir="ltr"><div>I get this result by applying only these transformations -mem2reg -lcssa -simplifycfg, maybe they are sufficient, -reassociate helps and returns 0. <br></div>So, if it MAXUINT-1, it is clear why it is zero or a big number when the first operand is negative.<br></div><div class="gmail_extra"><br><div class="gmail_quote">2017-07-31 11:02 GMT+02:00 Bruce Hoult <span dir="ltr"><<a href="mailto:bruce@hoult.org" target="_blank">bruce@hoult.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm surprised llvm (or clang) is emitting that -2 without a cast. But I'm sure it is treating it as MAXUINT-1 i.e. 0xfffffffe = 4294967294 on a 32 bit machine.<div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Mon, Jul 31, 2017 at 11:56 AM, Anastasiya Ruzhanskaya via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div><div><div><div><div><div><div><div>Hello,<br></div>I want to know, if I can always assume that when I do unsigned operations like <br><br></div>udiv, urem<br><br></div>I will get the both operands converted to unsigned values? with under optimized version of code I sometimes receive these lines:<br> unsigned a = 123;<br> int b = -2;<br> int c = a / b;<br>-> %1 = udiv i32 123, -2<br><br></div>and get the result 0. Will it always be zero? or is it undefined? Somewhere I have read that it may produce garbage.<br></div>will it be zero in this case : %1 = udiv i32 -123, 2?<br><br></div><div>However, when I set only the result as unsigned, then :<br> int a = 123;<br> int b = -2;<br> unsigned int c = a / b;<br>-> %1 = sdiv i32 123, -2 <br></div><div>the result seems to be correct. So one operand (not the result variable) needs to be unsigned in order the result was unsigned too? <br></div><div><br></div>What should I expect from sign of the operand if I get the line:<br>%1 = udiv i32 %a.o, 2. Can it in this case be negative. Or this situation is only the result of under optimization and zero value is ok?<br><br></div>These questions may be related mostly to c, but still, perhaps llvm has some additional rules that I didn't find. The general thing I wanted to know what to expect from sign of value when I get urem/udiv ops in final code? <br><br></div>Thank you in advance for the answer.<br></div>
<br></div></div>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>