https://gcc.gnu.org/g:d692d443714fd75ee70e0378f8a0db14b1dcbef6
commit r17-5910-gd692d443714fd75ee70e0378f8a0db14b1dcbef6 Author: Jeff Law <[email protected]> Date: Tue Nov 3 22:15:29 2026 -0700 [committed][PR target/128420] Convert RISC-V define_insn_and_split to simpler define_split LLM review of x264 found a case where we had code like this: lui a5,%hi(tab) andi a4,a0,3 addi t0,a5,%lo(tab) sh2add t1,a4,t0 lbu t2,0(t1) andi a0,a0,3 [ ... ] Note the two ANDI instructions. They compute the same value and put it into two different places. One is coming from a define_insn_and_split and thus we don't see it early enough to have any chance of optimizing it away. Turning that pattern into a simple define_split doesn't fix the problem, but it is a necessary step and it fits into the long term desire to avoid define_insn_and_split when we can. Implemented thusly. Tested on riscv32-elf and riscv64-elf. Bootstrap on K3 and C920 in flight. K1 is queued. Pushing to the trunk. PR target/128420 gcc/ * config/riscv/bitmanip.md (andi_add.uw): Turn into define_split. Diff: --- gcc/config/riscv/bitmanip.md | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index b3550d9a0d07..1482cee29a08 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -91,25 +91,20 @@ ; Make sure that an andi followed by a sh[123]add remains a two instruction ; sequence--and is not torn apart into slli, slri, add. -(define_insn_and_split "*andi_add.uw" - [(set (match_operand:DI 0 "register_operand" "=r") - (plus:DI (and:DI (ashift:DI (match_operand:DI 1 "register_operand" "r") - (match_operand:QI 2 "imm123_operand" "Ds3")) - (match_operand:DI 3 "consecutive_bits_operand" "")) - (match_operand:DI 4 "register_operand" "r"))) - (clobber (match_scratch:DI 5 "=&r"))] +(define_split + [(set (match_operand:DI 0 "register_operand") + (plus:DI (and:DI (ashift:DI (match_operand:DI 1 "register_operand") + (match_operand:QI 2 "imm123_operand")) + (match_operand:DI 3 "consecutive_bits_operand")) + (match_operand:DI 4 "register_operand"))) + (clobber (match_operand:DI 5 "register_operand"))] "TARGET_64BIT && TARGET_ZBA && riscv_shamt_matches_mask_p (INTVAL (operands[2]), INTVAL (operands[3])) && SMALL_OPERAND (INTVAL (operands[3]) >> INTVAL (operands[2]))" - "#" - "&& reload_completed" [(set (match_dup 5) (and:DI (match_dup 1) (match_dup 3))) (set (match_dup 0) (plus:DI (ashift:DI (match_dup 5) (match_dup 2)) (match_dup 4)))] -{ - operands[3] = GEN_INT (INTVAL (operands[3]) >> INTVAL (operands[2])); -} -[(set_attr "type" "bitmanip")]) + { operands[3] = GEN_INT (INTVAL (operands[3]) >> INTVAL (operands[2])); }) (define_insn "*shNadduw" [(set (match_operand:DI 0 "register_operand" "=r")
