This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] combine: Add added_notes_insn
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Segher Boessenkool <segher at kernel dot crashing dot org>
- Date: Mon, 6 Nov 2017 09:34:50 +0000
- Subject: [PATCH] combine: Add added_notes_insn
- Authentication-results: sourceware.org; auth=none
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 sset, 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 patch, it looks for very specific insns).
I'll commit this in a few days if no one complains.
Segher
2017-11-06 Segher Boessenkool <segher@kernel.crashing.org>
* 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.
---
gcc/combine.c | 32 +++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
diff --git a/gcc/combine.c b/gcc/combine.c
index 910d4b0..5d33378 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;
@@ -2816,6 +2820,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
@@ -4779,12 +4784,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. */
@@ -14661,10 +14667,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;
+ }
}
}
--
1.8.3.1