@@ -12521,6 +12521,59 @@ Example:
1252112521 %Y = ptrtoint ptr %P to i64 ; yields zero extension on 32-bit architecture
1252212522 %Z = ptrtoint <4 x ptr> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
1252312523
12524+ .. _i_ptrtoaddr:
12525+
12526+ '``ptrtoaddr .. to``' Instruction
12527+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12528+
12529+ Syntax:
12530+ """""""
12531+
12532+ ::
12533+
12534+ <result> = ptrtoaddr <ty> <value> to <ty2> ; yields ty2
12535+
12536+ Overview:
12537+ """""""""
12538+
12539+ The '``ptrtoaddr``' instruction converts the pointer or a vector of
12540+ pointers ``value`` to the underlying integer address (or vector of integers) of
12541+ type ``ty2``. This is different from :ref:`ptrtoint <i_ptrtoint>` in that it
12542+ only operates on the index bits of the pointer and ignores all other bits.
12543+ ``ty2`` must be the integer type (or vector of integers) matching the pointer
12544+ index width of the address space of ``ty``.
12545+
12546+ Arguments:
12547+ """"""""""
12548+
12549+ The '``ptrtoaddr``' instruction takes a ``value`` to cast, which must be
12550+ a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a
12551+ type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or
12552+ a vector of integers type.
12553+
12554+ Semantics:
12555+ """"""""""
12556+
12557+ The '``ptrtoaddr``' instruction converts ``value`` to integer type ``ty2`` by
12558+ interpreting the lowest index-width pointer representation bits as an integer.
12559+ If the address size and the pointer representation size are the same and
12560+ ``value`` and ``ty2`` are the same size, then nothing is done (*no-op cast*)
12561+ other than a type change.
12562+
12563+ The ``ptrtoaddr`` instruction always :ref:`captures the address but not the provenance <pointercapture>`
12564+ of the pointer argument.
12565+
12566+ Example:
12567+ """"""""
12568+ This example assumes pointers in address space 1 are 64 bits in size with an
12569+ address width of 32 bits (``p1:64:64:64:32`` :ref:`datalayout string<langref_datalayout>`)
12570+ .. code-block:: llvm
12571+
12572+ %X = ptrtoaddr ptr addrspace(1) %P to i8 ; extracts low 32 bits and truncates
12573+ %Y = ptrtoaddr ptr addrspace(1) %P to i64 ; extracts low 32 bits and zero extends
12574+ %Z = ptrtoaddr <4 x ptr addrspace(1)> %P to <4 x i64>; yields vector zero extension of low 32 bits for each pointer
12575+
12576+
1252412577.. _i_inttoptr:
1252512578
1252612579'``inttoptr .. to``' Instruction
0 commit comments