From 48ce740d3bfbd9a1a58b7283b730ed90c556b913 Mon Sep 17 00:00:00 2001 From: rsandifo Date: Wed, 3 Jan 2018 21:46:30 +0000 Subject: [PATCH] Improve spilling for variable-width slots Once SVE is enabled, a general AArch64 spill slot offset will be A + B * VL where A is a constant and B is a multiple of the SVE vector length. The offsets in SVE load and store instructions are a multiple of VL (and so can encode some values of B), while offsets for standard AArch64 load and store instructions aren't (and encode some values of A). We therefore get better spill code if variable-sized slots are grouped together separately from constant-sized slots, and if variable-sized slots are not reused for constant-sized data. Then, spills to the constant-sized slots can add B * VL to the offset first, creating a common anchor point for spills with the same B component but different A components. Similarly, spills to variable-sized slots can add A to the offset first, creating a common anchor point for spills with the same A component but different B components. This patch implements the sorting and grouping side of the optimisation. A later patch creates the anchor points. The patch is a no-op on other targets. 2018-01-03 Richard Sandiford Alan Hayward David Sherwood gcc/ * lra-spills.c (pseudo_reg_slot_compare): Sort slots by whether they are variable or constant sized. (assign_stack_slot_num_and_sort_pseudos): Don't reuse variable-sized slots for constant-sized data. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@256208 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 9 +++++++++ gcc/lra-spills.c | 27 ++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e273614bf13..a151f622738 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -2,6 +2,15 @@ Alan Hayward David Sherwood + * lra-spills.c (pseudo_reg_slot_compare): Sort slots by whether + they are variable or constant sized. + (assign_stack_slot_num_and_sort_pseudos): Don't reuse variable-sized + slots for constant-sized data. + +2018-01-03 Richard Sandiford + Alan Hayward + David Sherwood + * tree-vect-patterns.c (vect_recog_mask_conversion_pattern): When handling COND_EXPRs with boolean comparisons, try to find a better basis for the mask type than the boolean itself. diff --git a/gcc/lra-spills.c b/gcc/lra-spills.c index 64162c76e1a..67675d9f1c4 100644 --- a/gcc/lra-spills.c +++ b/gcc/lra-spills.c @@ -174,9 +174,17 @@ regno_freq_compare (const void *v1p, const void *v2p) } /* Sort pseudos according to their slots, putting the slots in the order - that they should be allocated. Slots with lower numbers have the highest - priority and should get the smallest displacement from the stack or - frame pointer (whichever is being used). + that they should be allocated. + + First prefer to group slots with variable sizes together and slots + with constant sizes together, since that usually makes them easier + to address from a common anchor point. E.g. loads of polynomial-sized + registers tend to take polynomial offsets while loads of constant-sized + registers tend to take constant (non-polynomial) offsets. + + Next, slots with lower numbers have the highest priority and should + get the smallest displacement from the stack or frame pointer + (whichever is being used). The first allocated slot is always closest to the frame pointer, so prefer lower slot numbers when frame_pointer_needed. If the stack @@ -194,6 +202,10 @@ pseudo_reg_slot_compare (const void *v1p, const void *v2p) slot_num1 = pseudo_slots[regno1].slot_num; slot_num2 = pseudo_slots[regno2].slot_num; + diff = (int (slots[slot_num1].size.is_constant ()) + - int (slots[slot_num2].size.is_constant ())); + if (diff != 0) + return diff; if ((diff = slot_num1 - slot_num2) != 0) return (frame_pointer_needed || (!FRAME_GROWS_DOWNWARD) == STACK_GROWS_DOWNWARD ? diff : -diff); @@ -356,8 +368,17 @@ assign_stack_slot_num_and_sort_pseudos (int *pseudo_regnos, int n) j = slots_num; else { + machine_mode mode + = wider_subreg_mode (PSEUDO_REGNO_MODE (regno), + lra_reg_info[regno].biggest_mode); for (j = 0; j < slots_num; j++) if (slots[j].hard_regno < 0 + /* Although it's possible to share slots between modes + with constant and non-constant widths, we usually + get better spill code by keeping the constant and + non-constant areas separate. */ + && (GET_MODE_SIZE (mode).is_constant () + == slots[j].size.is_constant ()) && ! (lra_intersected_live_ranges_p (slots[j].live_ranges, lra_reg_info[regno].live_ranges))) -- 2.11.4.GIT