<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>