This patch tweaks the code generated on POWER for integer multiplications by a constant, by making use of rldimi instructions. Much like x86's lea instruction, rldimi can be used to implement a shift and add pair in some circumstances. For rldimi this is when the shifted operand is known to have no bits in common with the added operand. Hence for the new testcase below: int foo(int x) { int t = x & 42; return t * 0x2001; } when compiled with -O2, GCC currently generates: andi. 3,3,0x2a slwi 9,3,13 add 3,9,3 extsw 3,3 blr with this patch, we now generate: andi. 3,3,0x2a rlwimi 3,3,13,0,31-13 extsw 3,3 blr It turns out this optimization already exists in the form of a combine splitter in rs6000.md, but the constraints on combine splitters, requiring three of four input instructions (and generating one or two output instructions) mean it doesn't get applied as often as it could. This patch converts the define_split into a define_insn_and_split to catch more cases (such as the one above). The one bit that's tricky/controversial is the use of RTL's nonzero_bits which is accurate during the combine pass when this pattern is first recognized, but not as advanced (not kept up to date) when this pattern is eventually split. To support this, I've used a "|| reload_completed" idiom. Does this approach seem reasonable? [I've another patch of x86 that uses the same idiom]. This patch has been tested on powerpc64le-unknown-linux-gnu with make bootstrap and make -k check with no new failures. Ok for mainline? 2022-06-26 Roger Sayle gcc/ChangeLog * config/rs6000/rs6000.md (*rotl3_insert_3b_): New define_insn_and_split created from exisiting define_split. gcc/testsuite/ChangeLog * gcc.target/powerpc/rldimi-3.c: New test case. Thanks in advance, Roger --