[LLVMdev] ptrtoint

Duncan P. N. Exon Smith dexonsmith at apple.com
Mon Sep 29 15:11:31 PDT 2014


> On Sep 29, 2014, at 2:29 PM, reed kotler <rkotler at mips.com> wrote:
> 
> Thanks.
> 
> So what about a fragment like this: (taken from fast-isel.ll in X86 )
> 
> define void @ptrtoint_i1(i8* %p, i1* %q) nounwind {
>  %t = ptrtoint i8* %p to i1
>  store i1 %t, i1* %q
>  ret void
> }

Intuitively, this looks like:

    void ptrtoint_i1(char *p, bool *q) { *q = (bool)p; }

However, `q` needs to be addressable in C/C++, so it's left as an `i8`.

`git log` suggests this particular testcase evolved incrementally out
of hand-written IR.

Why do you need C/C++ code for it?  Just interested?

> TIA.
> 
> On 09/29/2014 02:16 PM, Duncan P. N. Exon Smith wrote:
>>> On Sep 29, 2014, at 1:51 PM, reed kotler <rkotler at mips.com> wrote:
>>> 
>>> What kind of C or C++ code will emit a "ptrtoint" op?
>> This C code:
>> 
>>     long ptrtoint(void *p) { return (long)p; }
>> 
>> gives:
>> 
>>     define i64 @ptrtoint(i8* %p) {
>>       %1 = ptrtoint i8* %p to i64
>>       ret i64 %1
>>     }
>> 
>> 
>>> Also, what causes i1 to be emitted?
>> This C++ code:
>> 
>>     bool i1() { return false; }
>> 
>> gives:
>> 
>>     define zeroext i1 @_Z2i1v() {
>>       ret i1 false
>>     }
>> 
>> 
>>> Tia.
>>> 
>>> Reed
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> 




More information about the llvm-dev mailing list