https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112995
--- Comment #1 from Kewen Lin <linkw at gcc dot gnu.org> --- Initially we have: (insn 31 6 10 2 (set (reg/v:SI 9 9 [orig:119 c ] [119]) (reg/v:SI 64 0 [orig:119 c ] [119])) "test.i":5:5 555 {*movsi_internal1} (expr_list:REG_DEAD (reg/v:SI 64 0 [orig:119 c ] [119]) (nil))) (insn 10 31 25 2 (set (reg:DI 10 10 [128]) (ashift:DI (sign_extend:DI (reg/v:SI 9 9 [orig:119 c ] [119])) (const_int 2 [0x2]))) "test.i":7:8 278 {ashdi3_extswsli} (nil)) (insn 25 10 27 2 (set (reg:DI 64 0 [135]) (sign_extend:DI (reg/v:SI 9 9 [orig:119 c ] [119]))) "test.i":6:5 31 {extendsidi2} (expr_list:REG_DEAD (reg/v:SI 9 9 [orig:119 c ] [119]) (nil))) with moving up, we have: (insn 46 0 0 (set (reg:DI 64 0 [135]) (sign_extend:DI (reg/v:SI 64 0 [orig:119 c ] [119]))) 31 {extendsidi2} (expr_list:REG_DEAD (reg/v:SI 9 9 [orig:119 c ] [119]) (nil))) in try_replace_dest_reg, we updated the above EXPR_INSN_RTX to: (insn 48 0 0 (set (reg:DI 32 0) (sign_extend:DI (reg/v:SI 64 0 [orig:119 c ] [119]))) 31 {extendsidi2} (nil)) This doesn't match any constraint and it's an unexpected modification. Unfortunately function try_replace_dest_reg just checks the orig insn with: if (REGNO (best_reg) != REGNO (INSN_LHS (orig_insn)) && (! replace_src_with_reg_ok_p (orig_insn, best_reg) || ! replace_dest_with_reg_ok_p (orig_insn, best_reg))) But it doesn't check EXPR_INSN_RTX, I think it's under the assumption that if the original insn is able to be replaced then the change on EXPR_INSN_RTX is fine, but this isn't true as the given test case shows.