Skip to content

Commit eb812d2

Browse files
authored
[X86] Put R20/R21/R28/R29 later in GR64 list (#120510)
Because these registers require an extra byte to encode in certain memory form. Putting them later in the list will reduce code size when EGPR is enabled. And align the same order in GR8, GR16 and GR32 lists. Example: movq (%r20), %r11 # encoding: [0xd5,0x1c,0x8b,0x1c,0x24] movq (%r22), %r11 # encoding: [0xd5,0x1c,0x8b,0x1e]
1 parent 6586c67 commit eb812d2

File tree

2 files changed

+731
-731
lines changed

2 files changed

+731
-731
lines changed

llvm/lib/Target/X86/X86RegisterInfo.td

+13-13
Original file line numberDiff line numberDiff line change
@@ -541,18 +541,18 @@ def SSP : X86Reg<"ssp", 0>;
541541
// R12, R13, R14, and R15 for X86-64) are callee-save registers.
542542
// In 64-mode, there are 12 additional i8 registers, SIL, DIL, BPL, SPL, and
543543
// R8B, ... R15B.
544-
// Allocate R12 and R13 last, as these require an extra byte when
545-
// encoded in x86_64 instructions.
544+
// Allocate R12, R13, R20, R21, R28 and R29 last, as these require an extra byte
545+
// when encoded in x86_64 instructions.
546546
// FIXME: Allow AH, CH, DH, BH to be used as general-purpose registers in
547547
// 64-bit mode. The main complication is that they cannot be encoded in an
548548
// instruction requiring a REX prefix, while SIL, DIL, BPL, R8D, etc.
549549
// require a REX prefix. For example, "addb %ah, %dil" and "movzbl %ah, %r8d"
550550
// cannot be encoded.
551551
def GR8 : RegisterClass<"X86", [i8], 8,
552552
(add AL, CL, DL, AH, CH, DH, BL, BH, SIL, DIL, BPL, SPL,
553-
R8B, R9B, R10B, R11B, R16B, R17B, R18B, R19B, R20B,
554-
R21B, R22B, R23B, R24B, R25B, R26B, R27B, R28B, R29B,
555-
R30B, R31B, R14B, R15B, R12B, R13B)> {
553+
R8B, R9B, R10B, R11B, R16B, R17B, R18B, R19B, R22B,
554+
R23B, R24B, R25B, R26B, R27B, R30B, R31B, R14B,
555+
R15B, R12B, R13B, R20B, R21B, R28B, R29B)> {
556556
let AltOrders = [(sub GR8, AH, BH, CH, DH)];
557557
let AltOrderSelect = [{
558558
return MF.getSubtarget<X86Subtarget>().is64Bit();
@@ -567,9 +567,9 @@ def GRH8 : RegisterClass<"X86", [i8], 8,
567567
R26BH, R27BH, R28BH, R29BH, R30BH, R31BH)>;
568568
def GR16 : RegisterClass<"X86", [i16], 16,
569569
(add AX, CX, DX, SI, DI, BX, BP, SP, R8W, R9W, R10W,
570-
R11W, R16W, R17W, R18W, R19W, R20W, R21W, R22W, R23W,
571-
R24W, R25W, R26W, R27W, R28W, R29W, R30W, R31W, R14W,
572-
R15W, R12W, R13W)>;
570+
R11W, R16W, R17W, R18W, R19W, R22W, R23W, R24W,
571+
R25W, R26W, R27W, R30W, R31W, R14W, R15W, R12W,
572+
R13W, R20W, R21W, R28W, R29W)>;
573573

574574
let isAllocatable = 0 in
575575
def GRH16 : RegisterClass<"X86", [i16], 16,
@@ -579,9 +579,9 @@ def GRH16 : RegisterClass<"X86", [i16], 16,
579579
R25WH, R26WH, R27WH, R28WH, R29WH, R30WH, R31WH)>;
580580
def GR32 : RegisterClass<"X86", [i32], 32,
581581
(add EAX, ECX, EDX, ESI, EDI, EBX, EBP, ESP, R8D, R9D,
582-
R10D, R11D, R16D, R17D, R18D, R19D, R20D, R21D, R22D,
583-
R23D, R24D, R25D, R26D, R27D, R28D, R29D, R30D, R31D,
584-
R14D, R15D, R12D, R13D)>;
582+
R10D, R11D, R16D, R17D, R18D, R19D, R22D, R23D,
583+
R24D, R25D, R26D, R27D, R30D, R31D, R14D, R15D,
584+
R12D, R13D, R20D, R21D, R28D, R29D)>;
585585

586586
// GR64 - 64-bit GPRs. This oddly includes RIP, which isn't accurate, since
587587
// RIP isn't really a register and it can't be used anywhere except in an
@@ -590,8 +590,8 @@ def GR32 : RegisterClass<"X86", [i32], 32,
590590
// tests because of the inclusion of RIP in this register class.
591591
def GR64 : RegisterClass<"X86", [i64], 64,
592592
(add RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11, R16, R17,
593-
R18, R19, R20, R21, R22, R23, R24, R25, R26, R27, R28, R29,
594-
R30, R31, RBX, R14, R15, R12, R13, RBP, RSP, RIP)>;
593+
R18, R19, R22, R23, R24, R25, R26, R27, R30, R31, RBX,
594+
R14, R15, R12, R13, R20, R21, R28, R29, RBP, RSP, RIP)>;
595595

596596
// GR64PLTSafe - 64-bit GPRs without R10, R11, RSP and RIP. Could be used when
597597
// emitting code for intrinsics, which use implict input registers.

0 commit comments

Comments
 (0)