From 7e1e4fa469143ccefd1faa21a48acde205290e76 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 16 Mar 2016 08:35:22 +1030 Subject: [PATCH] Fix thinko in indirect_jump_optimize PR rtl-optimization/69195 PR rtl-optimization/47992 * ira.c (indirect_jump_optimize): Ignore artificial defs. Add comments. From-SVN: r234237 --- gcc/ChangeLog | 7 +++++++ gcc/ira.c | 26 ++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1225cac52f7a..7386bededf13 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2016-03-16 Alan Modra + + PR rtl-optimization/69195 + PR rtl-optimization/47992 + * ira.c (indirect_jump_optimize): Ignore artificial defs. + Add comments. + 2016-03-15 Bernd Schmidt Backport from mainline diff --git a/gcc/ira.c b/gcc/ira.c index f994897cb63a..2c00990ff283 100644 --- a/gcc/ira.c +++ b/gcc/ira.c @@ -3926,7 +3926,8 @@ update_equiv_regs (void) free (pdx_subregs); } -/* A pass over indirect jumps, converting simple cases to direct jumps. */ +/* A pass over indirect jumps, converting simple cases to direct jumps. + Combine does this optimization too, but only within a basic block. */ static void indirect_jump_optimize (void) { @@ -3946,14 +3947,23 @@ indirect_jump_optimize (void) int regno = REGNO (SET_SRC (x)); if (DF_REG_DEF_COUNT (regno) == 1) { - rtx def_insn = DF_REF_INSN (DF_REG_DEF_CHAIN (regno)); - rtx note = find_reg_note (def_insn, REG_LABEL_OPERAND, NULL_RTX); - - if (note) + df_ref def = DF_REG_DEF_CHAIN (regno); + if (!DF_REF_IS_ARTIFICIAL (def)) { - rtx lab = gen_rtx_LABEL_REF (Pmode, XEXP (note, 0)); - if (validate_replace_rtx (SET_SRC (x), lab, insn)) - rebuild_p = true; + rtx def_insn = DF_REF_INSN (def); + rtx note = find_reg_note (def_insn, REG_LABEL_OPERAND, NULL_RTX); + + if (note) + { + /* Substitute a LABEL_REF to the label given by the + note rather than using SET_SRC of DEF_INSN. + DEF_INSN might be loading the label constant from + a constant pool, which isn't what we want in a + direct branch. */ + rtx lab = gen_rtx_LABEL_REF (Pmode, XEXP (note, 0)); + if (validate_replace_rtx (SET_SRC (x), lab, insn)) + rebuild_p = true; + } } } } -- 2.47.2