[llvm] [IR] Add initial support for the byte type (PR #178666)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 19 08:00:35 PST 2026


================
@@ -13010,15 +13050,44 @@ is always a *no-op cast* because no bits change with this
 conversion. The conversion is done as if the ``value`` had been stored
 to memory and read back as type ``ty2``. Pointer (or vector of
 pointers) types may only be converted to other pointer (or vector of
-pointers) types with the same address space through this instruction.
-To convert pointers to other types, use the :ref:`inttoptr <i_inttoptr>`
-or :ref:`ptrtoint <i_ptrtoint>` instructions first.
+pointers) types with the same address space or byte (or vector of bytes) types
+through this instruction. To convert pointers to other types, use the
+:ref:`inttoptr <i_inttoptr>` or :ref:`ptrtoint <i_ptrtoint>` instructions first.
 
 There is a caveat for bitcasts involving vector types in relation to
 endianness. For example ``bitcast <2 x i8> <value> to i16`` puts element zero
 of the vector in the least significant bits of the i16 for little-endian while
 element zero ends up in the most significant bits for big-endian.
 
+If ``value`` is of the :ref:`byte type <t_byte>`:
+
+* If ``value`` contains at least one ``poison`` bit, the cast result is
+
+    * ``poison``, if ``ty2`` is a scalar type.
+
+    * a vector where only the lanes containing at least one ``poison`` bit are
+      ``poison``, if ``ty2`` is a vector type. The values of the remaining
+      non-``poison`` lanes are given by bitcasting the bits of ``value``
+      corresponding to each lane (according to the target's endianness) to the
+      lane element type.
+
+* If ``value`` is any mix of (non-``poison``) pointer and non-pointer bits:
+
+    * If ``ty2`` is a non-pointer type, the provenance of the pointer bits is
+      stripped without being exposed, similarly to the
+      :ref:`ptrtoaddr <i_ptrtoaddr>` instruction.
+
+    * If ``ty2`` is a pointer type, then if all bits of ``value`` are from the
+      same pointer and are correctly ordered (there were no pointer bit swaps),
+      the cast result is that pointer. If all the bits are from the same pointer
+      and these are not correctly ordered, or if ``value`` is a mix of bits from
+      different pointers or a mix of pointer and non-pointer bits, the result is
+      a pointer without provenance. This pointer cannot be dereferenced, but can
+      be used in comparisons or :ref:`getelementptr <i_getelementptr>`
+      instructions.
+
+* Otherwise, the cast is a *no-op*.
----------------
nikic wrote:

The documentation for loads should probably contain a reference to bitcasts along the lines of "the behavior of loading a value that was previously stored with a different type is described in the bitcast section".

(Strictly speaking, all of this should probably be in the load section, as bitcast is defined in terms of the result of performing a store followed by a load. But didactically it may be more useful to keep it here.)

https://github.com/llvm/llvm-project/pull/178666


More information about the llvm-commits mailing list