@@ -12428,12 +12428,15 @@ Semantics:
1242812428""""""""""
1242912429
1243012430The '``ptrtoint``' instruction converts ``value`` to integer type
12431- ``ty2`` by interpreting the pointer value as an integer and either
12432- truncating or zero extending that value to the size of the integer type.
12431+ ``ty2`` by interpreting the all pointer representation bits as an integer
12432+ (equivalent to a ``bitcast``) and either truncating or zero extending that value
12433+ to the size of the integer type.
1243312434If ``value`` is smaller than ``ty2`` then a zero extension is done. If
1243412435``value`` is larger than ``ty2`` then a truncation is done. If they are
1243512436the same size, then nothing is done (*no-op cast*) other than a type
1243612437change.
12438+ The ``ptrtoint`` always :ref:`captures address and provenance <pointercapture>`
12439+ of the pointer argument.
1243712440
1243812441Example:
1243912442""""""""
@@ -12444,6 +12447,61 @@ Example:
1244412447 %Y = ptrtoint ptr %P to i64 ; yields zero extension on 32-bit architecture
1244512448 %Z = ptrtoint <4 x ptr> %P to <4 x i64>; yields vector zero extension for a vector of addresses on 32-bit architecture
1244612449
12450+ .. _i_ptrtoaddr:
12451+
12452+ '``ptrtoaddr .. to``' Instruction
12453+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12454+
12455+ Syntax:
12456+ """""""
12457+
12458+ ::
12459+
12460+ <result> = ptrtoaddr <ty> <value> to <ty2> ; yields ty2
12461+
12462+ Overview:
12463+ """""""""
12464+
12465+ The '``ptrtoaddr``' instruction converts the pointer or a vector of
12466+ pointers ``value`` to the underlying integer address (or vector of integers) of
12467+ type ``ty2``. This is different from :ref:`ptrtoint <i_ptrtoint>` in that it
12468+ only operates on the index bits of the pointer and ignores all other bits.
12469+
12470+ Arguments:
12471+ """"""""""
12472+
12473+ The '``ptrtoaddr``' instruction takes a ``value`` to cast, which must be
12474+ a value of type :ref:`pointer <t_pointer>` or a vector of pointers, and a
12475+ type to cast it to ``ty2``, which must be an :ref:`integer <t_integer>` or
12476+ a vector of integers type.
12477+
12478+ Semantics:
12479+ """"""""""
12480+
12481+ The '``ptrtoaddr``' instruction converts ``value`` to integer type
12482+ ``ty2`` by interpreting the lowest index-width pointer representation bits as an
12483+ integer and either truncating or zero extending that value to the size of the
12484+ integer type.
12485+ If the address of ``value`` is smaller than ``ty2`` then a zero extension is
12486+ done. If the address of ``value`` is larger than ``ty2`` then a truncation is
12487+ done. If the address size and the pointer representation size are the same and
12488+ ``value`` and ``ty2`` are the same size, then nothing is done (*no-op cast*)
12489+ other than a type change.
12490+
12491+ The ``ptrtoaddr`` always :ref:`captures the address (but not provenance) <pointercapture>`
12492+ of the pointer argument.
12493+
12494+ Example:
12495+ """"""""
12496+ This example assumes pointers in address space 1 are 64 bits in size with an
12497+ address width of 32 bits (``p1:64:64:64:32`` :ref:`datalayout string<langref_datalayout>`)
12498+ .. code-block:: llvm
12499+
12500+ %X = ptrtoaddr ptr addrspace(1) %P to i8 ; extracts low 32 bits and truncates
12501+ %Y = ptrtoaddr ptr addrspace(1) %P to i64 ; extracts low 32 bits and zero extends
12502+ %Z = ptrtoaddr <4 x ptr addrspace(1)> %P to <4 x i64>; yields vector zero extension of low 32 bits for each pointer
12503+
12504+
1244712505.. _i_inttoptr:
1244812506
1244912507'``inttoptr .. to``' Instruction
@@ -12488,6 +12546,9 @@ of the integer ``value``. If ``value`` is larger than the size of a
1248812546pointer then a truncation is done. If ``value`` is smaller than the size
1248912547of a pointer then a zero extension is done. If they are the same size,
1249012548nothing is done (*no-op cast*).
12549+ The behavior is equivalent to a ``bitcast``, however, the resulting value is not
12550+ guaranteed to be dereferenceable (e.g. if the result type is a
12551+ :ref:`non-integral pointers <nointptrtype>`).
1249112552
1249212553Example:
1249312554""""""""
0 commit comments