Skip to content

Commit 7e4622e

Browse files
committed
Align Matcher::_new_SP for better vector spilling
1 parent 663ad8d commit 7e4622e

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

src/hotspot/share/opto/chaitin.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class LRG : public ResourceObj {
143143

144144
private:
145145
// Number of registers this live range uses when it colors
146-
uint16_t _num_regs; // 2 for Longs and Doubles, 1 for all else
146+
uint16_t _num_regs; // byte size of the value divided by 4
147147
// except _num_regs is kill count for fat_proj
148148

149149
// For scalable register, num_regs may not be the actual physical register size.

src/hotspot/share/opto/matcher.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,16 @@ void Matcher::match( ) {
283283
_parm_regs[i].set_pair(reg2, reg1);
284284
}
285285

286-
// Finally, make sure the incoming arguments take up an even number of
287-
// words, in case the arguments or locals need to contain doubleword stack
288-
// slots. The rest of the system assumes that stack slot pairs (in
289-
// particular, in the spill area) which look aligned will in fact be
290-
// aligned relative to the stack pointer in the target machine. Double
291-
// stack slots will always be allocated aligned.
292-
_new_SP = OptoReg::Name(align_up(_in_arg_limit, (int)RegMask::SlotsPerLong));
286+
// Allocated register sets are aligned to their size. Offsets to the stack
287+
// pointer have to be aligned to the size of the access. For this _new_SP is
288+
// aligned to the size of the largest register set with the stack alignment as
289+
// limit and a minimum of SlotsPerLong (2).
290+
if (UseNewCode) {
291+
int vector_aligment = MIN2(C->max_vector_size(), stack_alignment_in_bytes()) / VMRegImpl::stack_slot_size;
292+
_new_SP = OptoReg::Name(align_up(_in_arg_limit, MAX2((int)RegMask::SlotsPerLong, vector_aligment)));
293+
} else {
294+
_new_SP = OptoReg::Name(align_up(_in_arg_limit, (int)RegMask::SlotsPerLong));
295+
}
293296

294297
// Compute highest outgoing stack argument as
295298
// _new_SP + out_preserve_stack_slots + max(outgoing argument size).

src/hotspot/share/opto/regmask.hpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,12 @@ class RegMask {
354354
}
355355

356356
// SlotsPerLong is 2, since slots are 32 bits and longs are 64 bits.
357-
// Also, consider the maximum alignment size for a normally allocated
358-
// value. Since we allocate register pairs but not register quads (at
359-
// present), this alignment is SlotsPerLong (== 2). A normally
360-
// aligned allocated register is either a single register, or a pair
361-
// of adjacent registers, the lower-numbered being even.
362-
// See also is_aligned_Pairs() below, and the padding added before
363-
// Matcher::_new_SP to keep allocated pairs aligned properly.
364-
// If we ever go to quad-word allocations, SlotsPerQuad will become
365-
// the controlling alignment constraint. Note that this alignment
366-
// requirement is internal to the allocator, and independent of any
357+
// We allocate single registers for 32 bit values and register pairs for 64
358+
// bit values. The number of registers allocated for vectors match their size. E.g. for 128 bit
359+
// vectors (VecX) we allocate a set of 4 registers. Allocated sets are adjacent and aligned.
360+
// See RegMask::find_first_set(), is_aligned_pairs(), is_aligned_sets(), and the padding added before
361+
// Matcher::_new_SP to keep allocated pairs and sets aligned properly.
362+
// Note that this alignment requirement is internal to the allocator, and independent of any
367363
// particular platform.
368364
enum { SlotsPerLong = 2,
369365
SlotsPerVecA = 4,

0 commit comments

Comments
 (0)