https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128459
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Kyrylo Tkachov <[email protected]>: https://gcc.gnu.org/g:7a8c1f2e3b16e0fc4c1f673f68581522f2709533 commit r17-6835-g7a8c1f2e3b16e0fc4c1f673f68581522f2709533 Author: Kyrylo Tkachov <[email protected]> Date: Mon Nov 9 16:31:52 2026 +0100 aarch64: Implement bitcompress and bitexpand optabs [PR128459] __builtin_bitcompressg and __builtin_bitexpandg compute a parallel bit extract and a parallel bit deposit. Without target support, they expand to a loop or to a long sequence of shifts and carry-less multiplies. SVE2 has BEXT and BDEP (FEAT_SVE_BitPerm) for these operations. They are also available in streaming mode with +ssve-bitperm. They work on vector elements. Extend the existing BDEP, BEXT and BGRP pattern to the scalar modes SImode and DImode. It takes the operands in the SIMD&FP registers and prints them as SVE registers with %Z, so only the first element is used. The register allocator moves the operands with FMOV. For __builtin_bitcompressg on uint32_t: fmov s31, w0 fmov s30, w1 bext z31.s, z31.s, z30.s fmov w0, s31 ret Types narrower than 32 bits use the 32-bit form after zero extension. Wider types use the generic expansion, which splits them into 64-bit operations. Add the optab expanders for SImode and DImode, guarded by TARGET_SVE_BITPERM. Add the effective-target check aarch64_sve2_bitperm_hw for the runtime tests. Bootstrapped and tested on aarch64-none-linux-gnu. gcc/ChangeLog: PR middle-end/128459 * config/aarch64/iterators.md (SVE_FULL_I_SCALAR): New mode iterator. * config/aarch64/aarch64-sve2.md (@aarch64_sve_<sve_int_op><mode>): Use SVE_FULL_I_SCALAR. Print the operands with %Z. (bitcompress<mode>3, bitexpand<mode>3): New expanders. gcc/testsuite/ChangeLog: PR middle-end/128459 * lib/target-supports.exp (check_effective_target_aarch64_sve2_bitperm_hw): New. * gcc.target/aarch64/sve2/bitperm_1.c: New test. * gcc.target/aarch64/sve2/bitperm_2.c: Likewise. * gcc.target/aarch64/sve2/bitperm_3.c: Likewise. * gcc.target/aarch64/sme/bitperm_1.c: Likewise. * gcc.target/aarch64/sme/bitperm_2.c: Likewise. Signed-off-by: Kyrylo Tkachov <[email protected]>
