[llvm] [APInt] Add `bitwiseParity`, `compressBits`, and `expandBits` operations (PR #200114)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu May 28 01:08:51 PDT 2026


================
@@ -2489,6 +2489,33 @@ LLVM_ABI APInt clmulr(const APInt &LHS, const APInt &RHS);
 /// clmulh(a, b) = clmulr(a, b) >> 1
 LLVM_ABI APInt clmulh(const APInt &LHS, const APInt &RHS);
 
+/// Compute the parity (inclusive prefix XOR) for each bit in V.
+/// This is equivalent to clmul(V, ~0).
+///
+/// Example:
+/// bitwiseParity(i4 0b1010) = 0b0110
+LLVM_ABI APInt bitwiseParity(const APInt &V);
+
+/// Perform a "compress" operation, also known as pext or bext.
+///
+/// Selects the bits from Val at the positions where Mask has a 1-bit, and
----------------
RKSimon wrote:

```suggestion
/// Selects the bits from /p Val at the positions where /p Mask has a 1-bit, and
```

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


More information about the llvm-commits mailing list