[PATCH] [Multiprecision Arithmetic Optimization] Teach SelectionDAG how to promote the integer carry result of {add, sub}{c, e} to a larger integer type.

Michael Gottesman mgottesman at apple.com
Tue Jun 18 11:14:57 PDT 2013


Hey Duncan.

Sorry for the delay. Attached is a patch which follows what you suggested on IRC. Specifically:

1. I updated the logic to handle the promotion of UADDO so that it just uses 1 getSetCC instead of truncating/zexting which is unnecessary since:

Addition:      x + y < x => carry
Subtraction: x - y > x => carry

2. I refactored out said method and used it to also handle the promotion of ADDC.

3. I implemented a similar algorithm for ADDE. Specifically for addition:

sum = x + y + c_in
carry = [(x & y) | ((x | y) & ~sum)]  >> ((sizeof(carry) << 3)-1)
         = [(x & y) | ((x | y) & (sum ^ -1))]  >> ((sizeof(carry) << 3)-1)

and for subtraction:

diff = x - y - c_in
carry = [(~x & y) | ((~x | y) & diff)] >> ((sizeof(carry) << 3)-1)
         = [((x ^ -1) & y) | (((x ^ -1) | y) & diff)  >> ((sizeof(carry) << 3)-1)]

Hows it look?

Michael



On May 26, 2013, at 1:35 PM, Michael Gottesman <mgottesman at apple.com> wrote:

> Chatted w/Duncan on IRC. I will follow the UADDO logic here (preparing patch).
> 
> Michael
> 
> On May 25, 2013, at 5:54 AM, Duncan Sands <duncan.sands at gmail.com> wrote:
> 
>> Hi Michael,
>> 
>>> Would zero extending just ResNo 0 be a satisfactory lowering (i.e. no inputs,
>>> just ResNo 0)?
>> 
>> do you mean not changing the node, just creating a node to extend ResNo 0?  If
>> so, that won't work: the legalizer will go into an infinite loop as it will keep
>> on trying to legalize the original node.
>> 
>> Ciao, Duncan.
>> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130618/779d6854/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Teach-SelectionDAG-how-to-promote-the-integer-argume.patch
Type: application/octet-stream
Size: 8720 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130618/779d6854/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130618/779d6854/attachment-0001.html>


More information about the llvm-commits mailing list