<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Apr 22, 2014, at 8:19 AM, Eric Christopher <<a href="mailto:echristo@gmail.com">echristo@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">The goal here is to complete the implementation of LLVM’s existing arithmetic with overflow intrinsics. It was originally llvm.sdiv.with.overflow. I objected to that name because it is technically not checking overflow, so I thought that name would be misleading. To me overflow on division means taking a numerator composed of two 64-bit operands and expecting a single 64-bit result (as with x86).<br><br></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">This is particularly unclear.</span></blockquote></div><div><br></div><div>The name of the intrinsic is not something we need to quibble over, but I'll try to clarify:</div><div><br></div>IDIV: <span style="font-size: 10pt;">Perform signed division of RDX:RAX by the contents of
a 64-bit register or memory location and store the
quotient in RAX and the remainder in RDX. </span><div><span style="font-size: 10pt;"><br></span></div><div><span style="font-size: 10pt;">So if, for example, the divisor is 1 and RDX is not the sign bit of RAW, we hit what I would call overflow.</span></div><div><span style="font-size: 10pt;"><br></span></div><div><div><font size="2">The LLVM division intrinsics don't deal with this issue, and I don’t want to confuse people into thinking they do. Rather, they implement the semantics of integer division that I think we want at the IR level </font><span style="font-size: small;"> </span><span style="font-size: small;">(where each operand is the same size as the result)</span><span style="font-size: small;">.</span></div><div><font size="2"><br></font></div><div><font size="2">div(x, 0) == 0</font></div><div><font size="2">sdiv(min<T>, -1) == min<T></font></div><div style="font-size: 10pt;"><br></div></div><div style="font-size: 10pt;"><div style="font-size: 12px;"><font size="2">(this happens to match arm64)</font></div><div><font size="2"><br></font></div></div><div><div><font size="2">The intrinsics return a boolean to indicate that "overflow" occured, just like all the other llvm.arith.with.overflow intrinsics.</font></div><div style="font-size: 10pt;"><br></div></div><div style="font-size: 10pt;">I think an llvm-dev posting will also summarize this.</div><div style="font-size: 10pt;"><br></div><div style="font-size: 10pt;">-Andy</div></body></html>