[PATCH] [ConstantRange] Add a smultiply method for signed multiply

James Molloy James.Molloy at arm.com
Sat Feb 21 11:38:02 PST 2015


Hi Sanjoy,

OK, I agree with you that abstractly the resulting range is sign independent. However, the algorithm to calculate the range isn’t; further up the thread we suggested that the lower bound of the resulting range is the minimum of the cartesian product of the lowers and uppers of the inputs:

lower_multiply(a, b)  = min(
  [a.lower * b.lower, a.lower * b.upper, a.upper * b.lower, a.upper * b.upper]
);

Similarly for the upper bound substituting min with max. Surely here a signed minimum would produce a different value to an unsigned minimum?

Thanks for bearing with me, I feel like I’m being rather slow on the uptake here.

Cheers,

James


On 21 Feb 2015, at 19:22, Sanjoy Das <sanjoy at playingwithpointers.com> wrote:

>> [-2,0) * [-4,4)
>> Consider the trivial case: i8 [254,0) * i8 [252,4). In signed arithmetic,we
>> get:
>> a[0] * b[0] = 8
>> a[1] * b[1] = 0
>> a[0] * b[1] = -8
>> a[1] * b[0] = 0
>
> I'm not sure this is correct -- a[0]*b[1] == 254 * 253 == i8 6 no?
> Maybe I misunderstood the subscript notation?
>
>> So depending on the signedness of the minimum/maximum operation, we get
>> different results. Therefore, we do need a signed version of multiply.
>
> The max and min operations are already signedness-dependent
> (ConstantRange has getSignedMax and getUnsignedMax as you know); but
> computing the resulting range shouldn't be.
>
> "i8 [254,0) * i8 [252,4)" is "i8 [250, 9)".  The signed max of the
> result range is 8 while the unsigned max of that same range is 255.
> Similar story for min.
>
> Now it is possible that due to some reason the result for i8 [254,0) *
> i8 [252,4) computed by ::multiply is more conservative than [250,9).
> In that case, it is ::multiply that should be fixed since we have a
> case where it can be taught to be compute a better result.
>
> -- Sanjoy
>


-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium.  Thank you.

ARM Limited, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No:  2557590
ARM Holdings plc, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No:  2548782





More information about the llvm-commits mailing list