From: Segher Boessenkool Date: Fri, 17 Nov 2017 14:53:29 +0000 (+0100) Subject: combine: Add added_notes_insn X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f1b7bc164cb370b15c6e62d65120e6494729ac0c;p=gcc.git combine: Add added_notes_insn This patch makes combine reconsider insns it added notes to. This matters for example if the note is a REG_DEAD; without the note the setter of the register has to be kept around in the result of combinations, so it cannot be a 2->1 combination, and the cost of the result is higher than without that extra set, so try_combine may refuse the combination with the set, but allow it without the set. This fixes a regression for powerpc: pr69946.c has started to fail after the bitfield expansion changes. GCC used to generate lwz 3,0(9) rlwinm 3,3,12,20,23 ori 3,3,0x11 rotldi 3,3,52 bl bar but now it does lwz 3,0(9) rldicr 3,3,32,3 srdi 3,3,48 ori 3,3,0x110 sldi 3,3,48 bl bar (an instruction too many). After this patch it is lwz 3,0(9) rlwinm 3,3,16,16,19 ori 3,3,0x110 sldi 3,3,48 bl bar (the testcase still does not pass, it looks for very specific insns). * combine.c (added_notes_insn): New. (try_combine): Handle added_notes_insn like added_links_insn. Rewrite return value code. (distribute_notes): Set added_notes_insn to the earliest insn we added a note to. From-SVN: r254875 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c0249e81aa5..c8e169044ef 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2017-11-17 Segher Boessenkool + + * combine.c (added_notes_insn): New. + (try_combine): Handle added_notes_insn like added_links_insn. + Rewrite return value code. + (distribute_notes): Set added_notes_insn to the earliest insn we added + a note to. + 2017-11-17 Segher Boessenkool PR rtl-optimization/82621 diff --git a/gcc/combine.c b/gcc/combine.c index 404cf33e9d0..ab515436fc8 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -302,6 +302,10 @@ static HARD_REG_SET newpat_used_regs; static rtx_insn *added_links_insn; +/* And similarly, for notes. */ + +static rtx_insn *added_notes_insn; + /* Basic block in which we are performing combines. */ static basic_block this_basic_block; static bool optimize_this_for_speed_p; @@ -2790,6 +2794,7 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0, std::swap (i1, i2); added_links_insn = 0; + added_notes_insn = 0; /* First check for one important special case that the code below will not handle. Namely, the case where I1 is zero, I2 is a PARALLEL @@ -4752,12 +4757,13 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0, combine_successes++; undo_commit (); - if (added_links_insn - && (newi2pat == 0 || DF_INSN_LUID (added_links_insn) < DF_INSN_LUID (i2)) - && DF_INSN_LUID (added_links_insn) < DF_INSN_LUID (i3)) - return added_links_insn; - else - return newi2pat ? i2 : i3; + rtx_insn *ret = newi2pat ? i2 : i3; + if (added_links_insn && DF_INSN_LUID (added_links_insn) < DF_INSN_LUID (ret)) + ret = added_links_insn; + if (added_notes_insn && DF_INSN_LUID (added_notes_insn) < DF_INSN_LUID (ret)) + ret = added_notes_insn; + + return ret; } /* Get a marker for undoing to the current state. */ @@ -14628,10 +14634,22 @@ distribute_notes (rtx notes, rtx_insn *from_insn, rtx_insn *i3, rtx_insn *i2, { XEXP (note, 1) = REG_NOTES (place); REG_NOTES (place) = note; + + /* Set added_notes_insn to the earliest insn we added a note to. */ + if (added_notes_insn == 0 + || DF_INSN_LUID (added_notes_insn) > DF_INSN_LUID (place)) + added_notes_insn = place; } if (place2) - add_shallow_copy_of_reg_note (place2, note); + { + add_shallow_copy_of_reg_note (place2, note); + + /* Set added_notes_insn to the earliest insn we added a note to. */ + if (added_notes_insn == 0 + || DF_INSN_LUID (added_notes_insn) > DF_INSN_LUID (place2)) + added_notes_insn = place2; + } } }