[llvm-dev] Reasoning about known bits of the absolute value of a signed integer
John Regehr via llvm-dev
llvm-dev at lists.llvm.org
Wed May 4 06:17:57 PDT 2016
Carlos, if you're trying to answer a question about integer ranges,
maybe LVI is a better match than ValueTracking? I recently added a
method that lets you ask LVI for the ConstantRange associated with a
value-- from there you might be able to figure out the thing that you
actually want.
John
On 5/3/16 6:31 PM, Carlos Liam via llvm-dev wrote:
> I'm trying to reason about how to find certain bit positions of the
> absolute value of a given integer value. Specifically, I want to know
> the highest possibly set bit and lowest possibly set bit of the absolute
> value, in order to find the range between the two.
>
> Note that I'm specifically trying to be as conservative as possible.
>
> This is what I have so far:
>
> If the sign bit of the original integer is a known 0 (known positive) -
> the highest possibly set bit is the highest bit not known to be zero,
> and the lowest possibly set bit is the lowest bit not known to be zero.
>
> If the sign bit of the original integer is a known 1 (known negative) -
> the highest possibly set bit is the one *to the left of* the *lowest*
> bit not known to be one (unless that would be the sign bit, in which
> case it is replaced with the bit to the right of the sign bit), and the
> lowest possibly set bit is the lowest bit not known to be zero, UNLESS
> *every* bit other than the sign bit is not known to be one, in which
> case the highest possibly set bit is the sign bit.
>
> If the sign bit of the original integer is unknown - same as if known
> negative, except the highest possibly set bit is initially the higher of
> the two rules for highest possibly set bit.
>
> Is this correct? Can it be less conservative in certain situations? Are
> there any times where we know that only one of the highest and lowest
> possibly set bits can actually be set?
>
> I apologize for any headaches this causes.
>
> - CL
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
More information about the llvm-dev
mailing list