[LLVMdev] Confuse on ptrtoint and load

weixuegong weixuegong at gmail.com
Thu Sep 12 18:48:31 PDT 2013

Hi, all

When I read the document of IR on llvm.org,
I found two instructions, "ptrtoint" and load.

Load, I think, is : when after allocating some
bytes in memory and storing some data into it, we could
use load to get the data, like this:

%0 = alloca i32
store i32 5, i32* %0
%1 = load i32* %0
so, the type of %1 is i32, and the value is 5, right?

And "ptrtoint" is:we cast it from ptr to int? Just like
"&" in c++ ? When we are doing like this:

%0 = alloca i32
store i32 5, i32* %0
%1 = ptrtoint i32* %0 to i32
No doubt, the type of %1 is i32. But what is the value of %1?
Is it just like "load", loading the value stored, or becoming a "var"
to store the address(not the real value stored in memory)?

If I want to get the value stored in memory, I should use load,
and if I want to get the addr of the ptr, use ptrtoint, am I right?

Could anyone tell me the difference between them clearly?

Best Regards

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130913/78d472df/attachment.html>

More information about the llvm-dev mailing list