[PATCH] [ConstantRange] Add a smultiply method for signed multiply
sanjoy at playingwithpointers.com
Sat Feb 21 11:22:25 PST 2015
> [-2,0) * [-4,4)
> Consider the trivial case: i8 [254,0) * i8 [252,4). In signed arithmetic,we
> a * b = 8
> a * b = 0
> a * b = -8
> a * b = 0
I'm not sure this is correct -- a*b == 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.
More information about the llvm-commits