[LLVMdev] "icmp sgt" when it should be "ugt" ?
Dan Gohman
gohman at apple.com
Tue Aug 2 11:49:14 PDT 2011
On Aug 2, 2011, at 8:53 AM, Duncan Sands wrote:
> Hi Eli,
>
>>>> Icmp sgt is correct.
>>>
>>> while ugt would be wrong, I think sgt is too!
>>>
>>> For example, suppose %buf is 0 and %bufLen is ~0U. Then %add.ptr is ~0U, and
>>> %cmp is true, so control branches to %if.then. However in the optimized version
>>> %cmp is false and control branches to %if.end.
>>>
>>> The GEP does have an inbounds attribute, I'm not sure if that is relevant here.
>>
>> It is relevant: in your proposed scenario, the GEP returns undef.
>
> by the way, is GEP arithmetic supposed to be signed or unsigned?
It's a mix of both.
Indices are signed, but the other operand is a pointer, and pointers
can be interpreted in a variety of ways. On one hand, pointers are
unsigned, since SIZE_MAX/2 and SIZE_MAX/2+1 are contiguous addresses,
while SIZE_MAX and SIZE_MAX+1 are not, because address 0 is special.
On the other hand, it's generally considered to be impossible to
allocate more than half the address space to a single object, so it
often works to analyze them as if they were signed.
Dan
More information about the llvm-dev
mailing list