@@ -12466,6 +12466,61 @@ Example:
1246612466 %Y = ptrtoint ptr %P to i64 ; yields zero extension on 32-bit architecture
1246712467 %Z = ptrtoint <4 x ptr> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
1246812468
12469+ .. _i_ptrtoaddr:
12470+
12471+ '``ptrtoaddr .. to``' Instruction
12472+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12473+
12474+ Syntax:
12475+ """""""
12476+
12477+ ::
12478+
12479+ <result> = ptrtoaddr <ty> <value> to <ty2> ; yields ty2
12480+
12481+ Overview:
12482+ """""""""
12483+
12484+ The '``ptrtoaddr``' instruction converts the pointer or a vector of
12485+ pointers ``value`` to the underlying integer address (or vector of integers) of
12486+ type ``ty2``. This is different from :ref:`ptrtoint <i_ptrtoint>` in that it
12487+ only operates on the index bits of the pointer and ignores all other bits.
12488+
12489+ Arguments:
12490+ """"""""""
12491+
12492+ The '``ptrtoaddr``' instruction takes a ``value`` to cast, which must be
12493+ a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a
12494+ type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or
12495+ a vector of integers type.
12496+
12497+ Semantics:
12498+ """"""""""
12499+
12500+ The '``ptrtoaddr``' instruction converts ``value`` to integer type
12501+ ``ty2`` by interpreting the lowest index-width pointer representation bits as an
12502+ integer and either truncating or zero extending that value to the size of the
12503+ integer type.
12504+ If the address of ``value`` is smaller than ``ty2`` then a zero extension is
12505+ done. If the address of ``value`` is larger than ``ty2`` then a truncation is
12506+ done. If the address size and the pointer representation size are the same and
12507+ ``value`` and ``ty2`` are the same size, then nothing is done (*no-op cast*)
12508+ other than a type change.
12509+
12510+ The ``ptrtoaddr`` always :ref:`captures the address (but not provenance) <pointercapture>`
12511+ of the pointer argument.
12512+
12513+ Example:
12514+ """"""""
12515+ This example assumes pointers in address space 1 are 64 bits in size with an
12516+ address width of 32 bits (``p1:64:64:64:32`` :ref:`datalayout string<langref_datalayout>`)
12517+ .. code-block:: llvm
12518+
12519+ %X = ptrtoaddr ptr addrspace(1) %P to i8 ; extracts low 32 bits and truncates
12520+ %Y = ptrtoaddr ptr addrspace(1) %P to i64 ; extracts low 32 bits and zero extends
12521+ %Z = ptrtoaddr <4 x ptr addrspace(1)> %P to <4 x i64>; yields vector zero extension of low 32 bits for each pointer
12522+
12523+
1246912524.. _i_inttoptr:
1247012525
1247112526'``inttoptr .. to``' Instruction
0 commit comments