<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div></div><div><br></div><div>The intrinsics give the results following the next rules:</div><div><ol><li>If the RHS is <i>0</i>, the return value is a pair <i>{0, 1}</i>.</li><li>If the intrinsic is for signed operation, the RHS is <i>-1</i> and the LHS is <i>SignedMinValue</i>, the intrinsic returns <i>{SignedMinValue, 1}</i>.</li><li>In other cases, the result value is <i>{LHS op RHS, 0}</i>, where <i>op</i> is <i>sdiv</i>, <i>udiv</i>,<i> srem</i>, and <i>urem</i>, depending on the intrinsic.</li></ol></div><div><br></div><div>Examples:</div><div><br></div><div><font face="Courier New">llvm.safe.sdiv.i32(i32 8, i32 3) </font>returns<font face="Courier New"> {i32 2, i1 0}.</font></div><div><font face="Courier New">llvm.safe.urem.i8(i8 18, i8 5) </font>returns<font face="Courier New"> {i8 3, i1 0}.</font></div><div><font face="Courier New">llvm.safe.srem.i8(i8 -128, i8 -1) </font>returns<font face="Courier New"> {i8 -128, i1 1}.</font></div><div><font face="Courier New">llvm.safe.urem.i8(i8 128, i8 0) </font>returns<font face="Courier New"> {i8 0, i1 1}.</font></div><div><font face="Courier New">llvm.safe.udiv.i8(i8 128, i8 255) </font>returns<font face="Courier New"> {i8 0, i1 0}.</font></div><div><br></div><div>Example of actual use:</div><div><br></div><div><font face="Courier New">  %divresult32 = type { i32, i1 }</font></div><div><font face="Courier New">...</font></div><div><div><font face="Courier New">  %divr = call %divresult32 @llvm.safe.sdiv.i32(i32 %x, i32 %y)</font></div><div><font face="Courier New">  %div = extractvalue %divresult32 %divr, 0</font></div><div><font face="Courier New">  %bit = extractvalue %divresult32 %divr, 1</font></div><div><font face="Courier New">  br i1 %bit, label %trap.bb, label %ok.bb</font></div><div><font face="Courier New">trap.bb:</font></div><div><font face="Courier New">  call void @abort()</font></div><div><font face="Courier New">ok.bb:</font></div><div><font face="Courier New">  ret i32 %div</font></div></div><div><br></div><div>The implementation also tries to propagate the computed results to the users. It expects that the users are <i>extractvalue</i> instructions, otherwise it conservatively generates <i>alloca</i>+<i>stores</i>+<i>load</i>. If the propagation succeeds the resultant code becomes much cleaner and more efficient, especially on ARM64 where DIV instructions behave exactly the same way the intrinsic designed. To check whether DIV instruction behave this way or not, a new target hook was introduced.</div><div><br></div><div>The added tests are separated into two parts: the first one checks whether the full set of intrinsics is implemented, and the second one tests if the results propagation works correctly. The tests were added only for X86 and ARM64.</div><div><br></div><div>Is it ok to commit?</div><div><br></div><div>Thanks,</div><div>Michael</div></body></html>