On Wed, Oct 08, 2025 at 07:20:16PM +0530, Kishan Parmar wrote: > Ping! > > Please review. > > Thanks & Regards > Kishan > On 09/09/25 2:04 pm, Kishan Parmar wrote: > > Hi All, > > > > The fallback expansion of __builtin_bswap16 on pre-Power10 used a > > sequence of multiple rlwinm/or instructions: > > > > mr r9,r3 > > rlwinm r3,r9,24,24,31 > > rlwinm r10,r9,8,16,23 > > or r3,r3,r10 > > rlwinm r3,r3,0,0xffff > > > > This was functionally correct but less optimal. > > > > Rewrite the splitter to use a rotate-insert idiom, producing: > > > > mr r9,r3 > > slwi r3,r9,8 > > rlwimi r3,r9,24,24,31 > > rlwinm r3,r3,0,0xffff > > > > This sequence is shorter, maps directly to the rlwimi instruction. > > > > The following patch has been bootstrapped on powerpc64le-linux. > > > > 2025-09-09 Kishan Parmar <[email protected]> > > > > gcc/ > > PR target/121076 > > * config/rs6000/rs6000.md (bswaphi2_reg): Replace multi-instruction > > rotate-mask/rotate-mask/or sequence with shift/rotate-mask-insert > > idiom, reducing insn count for bswap16 on pre-Power10 targets.
This is ok to be installed in the GCC master branch right now. After a burn in period of 1 week if there are no issues with it on the master branch, you can apply it to all of the active GCC release branches, without needing a second review. It would be helpful to create a second patch that adds a test case for pr121076. You can check the patch in now, but do add a test case in the future. Note, care must be taken to specifiy that the codegen is for power8 or power9. In particular, if you use the -mdejagnu-cpu=power8, it won't override the default if the compiler was configured for power10 code generation (i.e. using the --with-cpu=power10 configuration option). You could explicitly use -mcpu=power8 on the target options instead of -mdejagnu-cpu=power8. Or you can use #pragma target option. See the PowerPC test case pragma_power8.c. -- Michael Meissner, IBM PO Box 98, Ayer, Massachusetts, USA, 01432 email: [email protected]
