<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;">(i.e. how said intrinsics are codegened as the IR level)<div><br><div><div>On Jun 28, 2013, at 3:14 PM, Michael Gottesman <<a href="mailto:mgottesman@apple.com">mgottesman@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: 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; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Look at the __builtin_addc* builtins in clang. I am currently working on an optimization which transforms said intrinsics into chains of ADCs/SBBs.<div><br></div><div>Michael</div><div><br><div><div>On Jun 28, 2013, at 5:51 AM, James Courtier-Dutton <<a href="mailto:james.dutton@gmail.com">james.dutton@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: 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;">Hi,<br><br>I have the x86 SBB instruction. how should I represent this in LLVM<br>IR.  (as part of a decompiler from binary to LLVM IR)<br><br>Pre-conditions:<br>%eax = 0xffffffff<br>%edx = 0xffffffff<br>%carry = 1<br><br>SBB %eax, %edx       // %edx is the destination doing %edx = %edx -<br>(%eax + carry)<br>JC  jump_destination1    // If the Carry flag is set, jump to jump_destination1<br><br>How do I represent this correctly in LLVM IR?<br>In the above case, the carry flag should be set by the SBB because:<br>%eax + carry == 0x100000000     (33 bits)  or 0x0 (32 bits)<br>%edx - (%eax + carry) == %edx   with Carry set.<br><br>If I use LLVM IR:<br>%eax2 = ADD i32 %eax1, %carry    (%eax2 == 0)<br>[%edx2,%carry] = llvm.ssub.with.overflow.i32 %edx1, %eax2    (carry ==<br>0, but I want it to be 1)<br><br>So, the problem only occurs with the edge case of %eax == 0xffffffff<br>and carry == 1<br><br>Any ideas how I could make this work accurately in LLVM IR ?<br>I could put an if round it:<br>if ((%eax1 == 0xffffffff)) && (%carry1 == 1)) {<br>   %carry2 = 1<br>} else {<br>%eax2 = ADD i32 %eax1, %carry<br>[%edx2,%carry3] = llvm.ssub.with.overflow.i32 %edx1, %eax2<br>}<br>%carry4 = phi (%carry2, %carry3)      (true branch, else branch)<br>%edx3 = phi (%edx1, %edx2)<br>branch cond %carry4  jump_destination<br><br>Any better ideas?<br><br>James<br>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a><span class="Apple-converted-space"> </span>        <a href="http://llvm.cs.uiuc.edu/">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a></div></blockquote></div></div></div></blockquote></div><br></div></body></html>