Hello! Before the recent patch to post-reload mode switching, vzeroupper insertion depended on the existence of the return copy instructions pair in functions that return a value. The first instruction in the pair represents a move to a function return hard register, and the second was a USE of the function return hard register. Sometimes a nop move was generated (e.g. %eax->%eax) for the first instruction of the return copy instructions pair and the patch [1] teached LRA to remove these useless instructions on the fly.
The removal caused optimize mode switching to trigger the assert, since the first instruction of a return pair was not found. The relevant part of the patch was later reverted. With the recent optimize mode switching patch, this is no longer necessary for vzeroupper insertion pass, so attached patch reverts the revert. 2018-11-21 Uros Bizjak <ubiz...@gmail.com> Revert the revert: 2013-10-26 Vladimir Makarov <vmaka...@redhat.com> Revert: 2013-10-25 Vladimir Makarov <vmaka...@redhat.com> * lra-spills.c (lra_final_code_change): Remove useless move insns. Patch was bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. OK for mainline? [1] https://gcc.gnu.org/ml/gcc-patches/2013-10/msg02208.html Uros.
diff --git a/gcc/lra-spills.c b/gcc/lra-spills.c index 33caf9f45649..008d7399687d 100644 --- a/gcc/lra-spills.c +++ b/gcc/lra-spills.c @@ -740,6 +740,7 @@ lra_final_code_change (void) int i, hard_regno; basic_block bb; rtx_insn *insn, *curr; + rtx set; int max_regno = max_reg_num (); for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++) @@ -818,5 +819,19 @@ lra_final_code_change (void) } if (insn_change_p) lra_update_operator_dups (id); + + if ((set = single_set (insn)) != NULL + && REG_P (SET_SRC (set)) && REG_P (SET_DEST (set)) + && REGNO (SET_SRC (set)) == REGNO (SET_DEST (set))) + { + /* Remove an useless move insn. IRA can generate move + insns involving pseudos. It is better remove them + earlier to speed up compiler a bit. It is also + better to do it here as they might not pass final RTL + check in LRA, (e.g. insn moving a control register + into itself). */ + lra_invalidate_insn_data (insn); + delete_insn (insn); + } } }