This patch cleans up the interface to df_ref_change_reg_with_loc. The function is used only by SET_REGNO_RAW, so the old regno is always REGNO (x) and the caller always goes on to set REGNO. (And the fuction doesn't make much sense otherwise.)
The patch therefore gets df_ref_change_reg_with_loc to work out the old regno itself and to install the new register number once it's done. The check for the old register being -1 was redundant. Only expr.c and postreload.c create -1 registers ("fixed" in a later patch). Both sites are just creating temporary registers in order to query backend hooks and neither site needs the check. expr.c does use SET_REGNO and so does go through this function, but only at a time when there's no df information. (And it wouldn't work if the df machinery were set up, since any change after the first would look like a "normal" change.) postreload.c uses SET_REGNO_RAW and so bypasses the code altogether. expr.c bypasses the code too by the end of the series. gcc/ * df.h (df_ref_change_reg_with_loc): Remove old_regno parameter. Change type of new_regno to unsigned int. * df-scan.c (df_ref_change_reg_with_loc_1): Change type of new_regno to unsigned int. (df_ref_change_reg_with_loc): Remove old_regno parameter. Change type of new_regno to unsigned int. Use SET_REGNO_RAW. * rtl.h (SET_REGNO): Update call to df_ref_change_reg_with_loc. (SET_REGNO_RAW): Add space after ",". Index: gcc/df.h =================================================================== --- gcc/df.h 2015-05-18 07:53:09.890871253 +0100 +++ gcc/df.h 2015-05-18 07:53:09.890871253 +0100 @@ -1049,7 +1049,7 @@ extern void df_recompute_luids (basic_bl extern void df_insn_change_bb (rtx_insn *, basic_block); extern void df_maybe_reorganize_use_refs (enum df_ref_order); extern void df_maybe_reorganize_def_refs (enum df_ref_order); -extern void df_ref_change_reg_with_loc (int, int, rtx); +extern void df_ref_change_reg_with_loc (rtx, unsigned int); extern void df_notes_rescan (rtx_insn *); extern void df_hard_reg_init (void); extern void df_update_entry_block_defs (void); Index: gcc/df-scan.c =================================================================== --- gcc/df-scan.c 2015-05-18 07:53:09.890871253 +0100 +++ gcc/df-scan.c 2015-05-18 07:53:09.890871253 +0100 @@ -1819,7 +1819,7 @@ df_insn_change_bb (rtx_insn *insn, basic static void df_ref_change_reg_with_loc_1 (struct df_reg_info *old_df, struct df_reg_info *new_df, - int new_regno, rtx loc) + unsigned int new_regno, rtx loc) { df_ref the_ref = old_df->reg_chain; @@ -1904,25 +1904,33 @@ df_ref_change_reg_with_loc_1 (struct df_ } -/* Change the regno of all refs that contained LOC from OLD_REGNO to - NEW_REGNO. Refs that do not match LOC are not changed which means - that artificial refs are not changed since they have no loc. This - call is to support the SET_REGNO macro. */ +/* Change the regno of register LOC to NEW_REGNO and update the df + information accordingly. Refs that do not match LOC are not changed + which means that artificial refs are not changed since they have no loc. + This call is to support the SET_REGNO macro. */ void -df_ref_change_reg_with_loc (int old_regno, int new_regno, rtx loc) +df_ref_change_reg_with_loc (rtx loc, unsigned int new_regno) { - if ((!df) || (old_regno == -1) || (old_regno == new_regno)) + unsigned int old_regno = REGNO (loc); + if (old_regno == new_regno) return; - df_grow_reg_info (); + if (df) + { + df_grow_reg_info (); - df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno), - DF_REG_DEF_GET (new_regno), new_regno, loc); - df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno), - DF_REG_USE_GET (new_regno), new_regno, loc); - df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno), - DF_REG_EQ_USE_GET (new_regno), new_regno, loc); + df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno), + DF_REG_DEF_GET (new_regno), + new_regno, loc); + df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno), + DF_REG_USE_GET (new_regno), + new_regno, loc); + df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno), + DF_REG_EQ_USE_GET (new_regno), + new_regno, loc); + } + SET_REGNO_RAW (loc, new_regno); } Index: gcc/rtl.h =================================================================== --- gcc/rtl.h 2015-05-18 07:53:09.890871253 +0100 +++ gcc/rtl.h 2015-05-18 07:53:09.886871176 +0100 @@ -1693,9 +1693,8 @@ #define LABEL_REF_LABEL(LABREF) XCEXP (L /* For a REG rtx, REGNO extracts the register number. REGNO can only be used on RHS. Use SET_REGNO to change the value. */ #define REGNO(RTX) (rhs_regno(RTX)) -#define SET_REGNO(RTX,N) \ - (df_ref_change_reg_with_loc (REGNO (RTX), N, RTX), XCUINT (RTX, 0, REG) = N) -#define SET_REGNO_RAW(RTX,N) (XCUINT (RTX, 0, REG) = N) +#define SET_REGNO(RTX, N) (df_ref_change_reg_with_loc (RTX, N)) +#define SET_REGNO_RAW(RTX, N) (XCUINT (RTX, 0, REG) = N) /* Return the number of consecutive registers in a REG. This is always 1 for pseudo registers and is determined by HARD_REGNO_NREGS for