[llvm] [IR] Implementation and lowering of bitinsert and bitextract (PR #200605)
Alexis Engelke via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 16 03:42:54 PDT 2026
================
@@ -11385,6 +11385,80 @@ The truth table used for the '`xor`' instruction is:
<result> = xor i32 %V, -1 ; yields i32:result = ~%V
```
+### Byte Operations
+
+Instructions for bit-range manipulation on {ref}`byte type <t_byte>` values.
+
+(i_bitextract)=
+
+#### '`bitextract`' Instruction
+
+##### Syntax:
+<result> = bitextract <ty>, <bty> <source>, i32 <offset>
+
+##### Overview:
+
+The '`bitextract`' instruction reads a contiguous range of bits from a
+{ref}`byte type <t_byte>` value and returns them as a value of type `ty`.
+
+##### Arguments:
+
+`<ty>` is any {ref}`single value type <t_single_value>` and specifies
+the result type. The first operand, `source`, must be a value of
+{ref}`byte type <t_byte>`. The `offset` operand is an `i32` giving
+the bit position at which the extraction begins within `source`.
+
+##### Semantics:
+
+The result is the bit range `source[offset : offset + bitwidth(ty))`,
+reinterpreted as a value of type `ty` as if by a `bitcast`.
+Bit `0` is the least significant bit of `source`.
+
+If `offset + bitwidth(ty)` is greater than `bitwidth(source)`,
+{ref}`poison value <poisonvalues>` is returned.
+
+##### Example:
+
+```text
+%result = bitextract i8, b32 %src, i32 24 ; Extract the 8 most-significant bits (bits [24..31]) of %src and return an 8-bit integer
+```
+
+(i_bitinsert)=
+
+#### '`bitinsert`' Instruction
+
+##### Syntax:
+<result> = bitinsert <bty> <base>, <ty> <val>, i32 <offset>
+
+##### Overview:
+
+The '`bitinsert`' instruction writes a contiguous range of bits from a
+{ref}`single value type <t_single_value>` value into a {ref}`byte type <t_byte>`
+value and returns the result as a value of the same byte type.
+
+##### Arguments:
+
+`<ty>` is any {ref}`single value type <t_single_value>` and specifies the
----------------
aengelke wrote:
When inserting pointers, is this more like ptrtoaddr or like ptrtoint? Forbid targetext types?
https://github.com/llvm/llvm-project/pull/200605
More information about the llvm-commits
mailing list