[llvm] [X86][MC] Allow to specify any of the 8/16/32/64 register names interchangeably for R16-R31 (PR #73421)
Shengchen Kan via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 26 17:42:50 PST 2023
https://github.com/KanRobert updated https://github.com/llvm/llvm-project/pull/73421
>From 42e48c5142c7a46d6efaaaf0849cc8c208d88448 Mon Sep 17 00:00:00 2001
From: Shengchen Kan <shengchen.kan at intel.com>
Date: Sun, 26 Nov 2023 10:47:44 +0800
Subject: [PATCH 1/2] [X86][MC] Allow to specify any of the 8/16/32/64 register
names interchangeably for R16-R31
---
.../X86/MCTargetDesc/X86MCTargetDesc.cpp | 64 +++++++++
llvm/test/CodeGen/X86/asm-mismatched-types.ll | 126 ++++++++++++++++++
2 files changed, 190 insertions(+)
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
index af5cb1215abcce8..3b4638afeaf11a5 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
@@ -817,6 +817,22 @@ MCRegister llvm::getX86SubSuperRegister(MCRegister Reg, unsigned Size,
NO_SUB_SUPER(13, R13B)
NO_SUB_SUPER(14, R14B)
NO_SUB_SUPER(15, R15B)
+ NO_SUB_SUPER(16, R16B)
+ NO_SUB_SUPER(17, R17B)
+ NO_SUB_SUPER(18, R18B)
+ NO_SUB_SUPER(19, R19B)
+ NO_SUB_SUPER(20, R20B)
+ NO_SUB_SUPER(21, R21B)
+ NO_SUB_SUPER(22, R22B)
+ NO_SUB_SUPER(23, R23B)
+ NO_SUB_SUPER(24, R24B)
+ NO_SUB_SUPER(25, R25B)
+ NO_SUB_SUPER(26, R26B)
+ NO_SUB_SUPER(27, R27B)
+ NO_SUB_SUPER(28, R28B)
+ NO_SUB_SUPER(29, R29B)
+ NO_SUB_SUPER(30, R30B)
+ NO_SUB_SUPER(31, R31B)
}
}
case 16:
@@ -838,6 +854,22 @@ MCRegister llvm::getX86SubSuperRegister(MCRegister Reg, unsigned Size,
NO_SUB_SUPER(13, R13W)
NO_SUB_SUPER(14, R14W)
NO_SUB_SUPER(15, R15W)
+ NO_SUB_SUPER(16, R16W)
+ NO_SUB_SUPER(17, R17W)
+ NO_SUB_SUPER(18, R18W)
+ NO_SUB_SUPER(19, R19W)
+ NO_SUB_SUPER(20, R20W)
+ NO_SUB_SUPER(21, R21W)
+ NO_SUB_SUPER(22, R22W)
+ NO_SUB_SUPER(23, R23W)
+ NO_SUB_SUPER(24, R24W)
+ NO_SUB_SUPER(25, R25W)
+ NO_SUB_SUPER(26, R26W)
+ NO_SUB_SUPER(27, R27W)
+ NO_SUB_SUPER(28, R28W)
+ NO_SUB_SUPER(29, R29W)
+ NO_SUB_SUPER(30, R30W)
+ NO_SUB_SUPER(31, R31W)
}
case 32:
switch (Reg.id()) {
@@ -858,6 +890,22 @@ MCRegister llvm::getX86SubSuperRegister(MCRegister Reg, unsigned Size,
NO_SUB_SUPER(13, R13D)
NO_SUB_SUPER(14, R14D)
NO_SUB_SUPER(15, R15D)
+ NO_SUB_SUPER(16, R16D)
+ NO_SUB_SUPER(17, R17D)
+ NO_SUB_SUPER(18, R18D)
+ NO_SUB_SUPER(19, R19D)
+ NO_SUB_SUPER(20, R20D)
+ NO_SUB_SUPER(21, R21D)
+ NO_SUB_SUPER(22, R22D)
+ NO_SUB_SUPER(23, R23D)
+ NO_SUB_SUPER(24, R24D)
+ NO_SUB_SUPER(25, R25D)
+ NO_SUB_SUPER(26, R26D)
+ NO_SUB_SUPER(27, R27D)
+ NO_SUB_SUPER(28, R28D)
+ NO_SUB_SUPER(29, R29D)
+ NO_SUB_SUPER(30, R30D)
+ NO_SUB_SUPER(31, R31D)
}
case 64:
switch (Reg.id()) {
@@ -878,6 +926,22 @@ MCRegister llvm::getX86SubSuperRegister(MCRegister Reg, unsigned Size,
NO_SUB_SUPER(13, R13)
NO_SUB_SUPER(14, R14)
NO_SUB_SUPER(15, R15)
+ NO_SUB_SUPER(16, R16)
+ NO_SUB_SUPER(17, R17)
+ NO_SUB_SUPER(18, R18)
+ NO_SUB_SUPER(19, R19)
+ NO_SUB_SUPER(20, R20)
+ NO_SUB_SUPER(21, R21)
+ NO_SUB_SUPER(22, R22)
+ NO_SUB_SUPER(23, R23)
+ NO_SUB_SUPER(24, R24)
+ NO_SUB_SUPER(25, R25)
+ NO_SUB_SUPER(26, R26)
+ NO_SUB_SUPER(27, R27)
+ NO_SUB_SUPER(28, R28)
+ NO_SUB_SUPER(29, R29)
+ NO_SUB_SUPER(30, R30)
+ NO_SUB_SUPER(31, R31)
}
}
}
diff --git a/llvm/test/CodeGen/X86/asm-mismatched-types.ll b/llvm/test/CodeGen/X86/asm-mismatched-types.ll
index 97f9c0872f8f50d..47525e025f1dc37 100644
--- a/llvm/test/CodeGen/X86/asm-mismatched-types.ll
+++ b/llvm/test/CodeGen/X86/asm-mismatched-types.ll
@@ -133,3 +133,129 @@ define void @reg8_as_16(i16 %p) {
call void asm sideeffect "# REG: $0", "{dil}"(i16 %p)
ret void
}
+
+; CHECK-LABEL: egpr_reg64_as_32:
+; CHECK: # REG: %r16d
+define void @egpr_reg64_as_32(i32 %p) {
+ call void asm sideeffect "# REG: $0", "{r16}"(i32 %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg64_as_32_float:
+; CHECK: # REG: %r16d
+define void @egpr_reg64_as_32_float(float %p) {
+ call void asm sideeffect "# REG: $0", "{r16}"(float %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg64_as_16:
+; CHECK: # REG: %r17w
+define void @egpr_reg64_as_16(i16 %p) {
+ call void asm sideeffect "# REG: $0", "{r17}"(i16 %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg64_as_8:
+; CHECK: # REG: %r21b
+define void @egpr_reg64_as_8(i8 %p) {
+ call void asm sideeffect "# REG: $0", "{r21}"(i8 %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg32_as_16:
+; CHECK: # REG: %r21w
+define void @egpr_reg32_as_16(i16 %p) {
+ call void asm sideeffect "# REG: $0", "{r21d}"(i16 %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg32_as_8:
+; CHECK: # REG: %r20b
+define void @egpr_reg32_as_8(i8 %p) {
+ call void asm sideeffect "# REG: $0", "{r20d}"(i8 %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg16_as_8:
+; CHECK: # REG: %r17b
+define void @egpr_reg16_as_8(i8 %p) {
+ call void asm sideeffect "# REG: $0", "{r17w}"(i8 %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg32_as_64:
+; CHECK: # REG: %r21
+define void @egpr_reg32_as_64(i64 %p) {
+ call void asm sideeffect "# REG: $0", "{r21d}"(i64 %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg32_as_64_float:
+; CHECK: # REG: %r21
+define void @egpr_reg32_as_64_float(double %p) {
+ call void asm sideeffect "# REG: $0", "{r21d}"(double %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg16_as_64:
+; CHECK: # REG: %r21
+define void @egpr_reg16_as_64(i64 %p) {
+ call void asm sideeffect "# REG: $0", "{r21w}"(i64 %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg16_as_64_float:
+; CHECK: # REG: %r21
+define void @egpr_reg16_as_64_float(double %p) {
+ call void asm sideeffect "# REG: $0", "{r21w}"(double %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg8_as_64:
+; CHECK: # REG: %r16
+define void @egpr_reg8_as_64(i64 %p) {
+ call void asm sideeffect "# REG: $0", "{r16b}"(i64 %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg8_as_64_float:
+; CHECK: # REG: %r16
+define void @egpr_reg8_as_64_float(double %p) {
+ call void asm sideeffect "# REG: $0", "{r16b}"(double %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg16_as_32:
+; CHECK: # REG: %r19d
+define void @egpr_reg16_as_32(i32 %p) {
+ call void asm sideeffect "# REG: $0", "{r19w}"(i32 %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg16_as_32_float:
+; CHECK: # REG: %r19d
+define void @egpr_reg16_as_32_float(float %p) {
+ call void asm sideeffect "# REG: $0", "{r19w}"(float %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg8_as_32:
+; CHECK: # REG: %r17d
+define void @egpr_reg8_as_32(i32 %p) {
+ call void asm sideeffect "# REG: $0", "{r17b}"(i32 %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg8_as_32_float:
+; CHECK: # REG: %r17d
+define void @egpr_reg8_as_32_float(float %p) {
+ call void asm sideeffect "# REG: $0", "{r17b}"(float %p)
+ ret void
+}
+
+; CHECK-LABEL: egpr_reg8_as_16:
+; CHECK: # REG: %r18w
+define void @egpr_reg8_as_16(i16 %p) {
+ call void asm sideeffect "# REG: $0", "{r18b}"(i16 %p)
+ ret void
+}
>From 09d8b08512d66b56dac99c6a002655d0aa7b3977 Mon Sep 17 00:00:00 2001
From: Shengchen Kan <shengchen.kan at intel.com>
Date: Mon, 27 Nov 2023 09:25:22 +0800
Subject: [PATCH 2/2] Address reivew comments
---
.../X86/MCTargetDesc/X86MCTargetDesc.cpp | 196 +++++++++---------
1 file changed, 100 insertions(+), 96 deletions(-)
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
index 3b4638afeaf11a5..165e9207ef1c28f 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
@@ -786,6 +786,10 @@ MCRegister llvm::getX86SubSuperRegister(MCRegister Reg, unsigned Size,
#define SP_SUB_SUPER(R) SUB_SUPER(SPL, SP, ESP, RSP, R)
#define NO_SUB_SUPER(NO, REG) \
SUB_SUPER(R##NO##B, R##NO##W, R##NO##D, R##NO, REG)
+#define NO_SUB_SUPER_B(NO) NO_SUB_SUPER(NO, R##NO##B)
+#define NO_SUB_SUPER_W(NO) NO_SUB_SUPER(NO, R##NO##W)
+#define NO_SUB_SUPER_D(NO) NO_SUB_SUPER(NO, R##NO##D)
+#define NO_SUB_SUPER_Q(NO) NO_SUB_SUPER(NO, R##NO)
switch (Size) {
default:
llvm_unreachable("illegal register size");
@@ -809,30 +813,30 @@ MCRegister llvm::getX86SubSuperRegister(MCRegister Reg, unsigned Size,
DI_SUB_SUPER(DIL)
BP_SUB_SUPER(BPL)
SP_SUB_SUPER(SPL)
- NO_SUB_SUPER(8, R8B)
- NO_SUB_SUPER(9, R9B)
- NO_SUB_SUPER(10, R10B)
- NO_SUB_SUPER(11, R11B)
- NO_SUB_SUPER(12, R12B)
- NO_SUB_SUPER(13, R13B)
- NO_SUB_SUPER(14, R14B)
- NO_SUB_SUPER(15, R15B)
- NO_SUB_SUPER(16, R16B)
- NO_SUB_SUPER(17, R17B)
- NO_SUB_SUPER(18, R18B)
- NO_SUB_SUPER(19, R19B)
- NO_SUB_SUPER(20, R20B)
- NO_SUB_SUPER(21, R21B)
- NO_SUB_SUPER(22, R22B)
- NO_SUB_SUPER(23, R23B)
- NO_SUB_SUPER(24, R24B)
- NO_SUB_SUPER(25, R25B)
- NO_SUB_SUPER(26, R26B)
- NO_SUB_SUPER(27, R27B)
- NO_SUB_SUPER(28, R28B)
- NO_SUB_SUPER(29, R29B)
- NO_SUB_SUPER(30, R30B)
- NO_SUB_SUPER(31, R31B)
+ NO_SUB_SUPER_B(8)
+ NO_SUB_SUPER_B(9)
+ NO_SUB_SUPER_B(10)
+ NO_SUB_SUPER_B(11)
+ NO_SUB_SUPER_B(12)
+ NO_SUB_SUPER_B(13)
+ NO_SUB_SUPER_B(14)
+ NO_SUB_SUPER_B(15)
+ NO_SUB_SUPER_B(16)
+ NO_SUB_SUPER_B(17)
+ NO_SUB_SUPER_B(18)
+ NO_SUB_SUPER_B(19)
+ NO_SUB_SUPER_B(20)
+ NO_SUB_SUPER_B(21)
+ NO_SUB_SUPER_B(22)
+ NO_SUB_SUPER_B(23)
+ NO_SUB_SUPER_B(24)
+ NO_SUB_SUPER_B(25)
+ NO_SUB_SUPER_B(26)
+ NO_SUB_SUPER_B(27)
+ NO_SUB_SUPER_B(28)
+ NO_SUB_SUPER_B(29)
+ NO_SUB_SUPER_B(30)
+ NO_SUB_SUPER_B(31)
}
}
case 16:
@@ -846,30 +850,30 @@ MCRegister llvm::getX86SubSuperRegister(MCRegister Reg, unsigned Size,
DI_SUB_SUPER(DI)
BP_SUB_SUPER(BP)
SP_SUB_SUPER(SP)
- NO_SUB_SUPER(8, R8W)
- NO_SUB_SUPER(9, R9W)
- NO_SUB_SUPER(10, R10W)
- NO_SUB_SUPER(11, R11W)
- NO_SUB_SUPER(12, R12W)
- NO_SUB_SUPER(13, R13W)
- NO_SUB_SUPER(14, R14W)
- NO_SUB_SUPER(15, R15W)
- NO_SUB_SUPER(16, R16W)
- NO_SUB_SUPER(17, R17W)
- NO_SUB_SUPER(18, R18W)
- NO_SUB_SUPER(19, R19W)
- NO_SUB_SUPER(20, R20W)
- NO_SUB_SUPER(21, R21W)
- NO_SUB_SUPER(22, R22W)
- NO_SUB_SUPER(23, R23W)
- NO_SUB_SUPER(24, R24W)
- NO_SUB_SUPER(25, R25W)
- NO_SUB_SUPER(26, R26W)
- NO_SUB_SUPER(27, R27W)
- NO_SUB_SUPER(28, R28W)
- NO_SUB_SUPER(29, R29W)
- NO_SUB_SUPER(30, R30W)
- NO_SUB_SUPER(31, R31W)
+ NO_SUB_SUPER_W(8)
+ NO_SUB_SUPER_W(9)
+ NO_SUB_SUPER_W(10)
+ NO_SUB_SUPER_W(11)
+ NO_SUB_SUPER_W(12)
+ NO_SUB_SUPER_W(13)
+ NO_SUB_SUPER_W(14)
+ NO_SUB_SUPER_W(15)
+ NO_SUB_SUPER_W(16)
+ NO_SUB_SUPER_W(17)
+ NO_SUB_SUPER_W(18)
+ NO_SUB_SUPER_W(19)
+ NO_SUB_SUPER_W(20)
+ NO_SUB_SUPER_W(21)
+ NO_SUB_SUPER_W(22)
+ NO_SUB_SUPER_W(23)
+ NO_SUB_SUPER_W(24)
+ NO_SUB_SUPER_W(25)
+ NO_SUB_SUPER_W(26)
+ NO_SUB_SUPER_W(27)
+ NO_SUB_SUPER_W(28)
+ NO_SUB_SUPER_W(29)
+ NO_SUB_SUPER_W(30)
+ NO_SUB_SUPER_W(31)
}
case 32:
switch (Reg.id()) {
@@ -882,30 +886,30 @@ MCRegister llvm::getX86SubSuperRegister(MCRegister Reg, unsigned Size,
DI_SUB_SUPER(EDI)
BP_SUB_SUPER(EBP)
SP_SUB_SUPER(ESP)
- NO_SUB_SUPER(8, R8D)
- NO_SUB_SUPER(9, R9D)
- NO_SUB_SUPER(10, R10D)
- NO_SUB_SUPER(11, R11D)
- NO_SUB_SUPER(12, R12D)
- NO_SUB_SUPER(13, R13D)
- NO_SUB_SUPER(14, R14D)
- NO_SUB_SUPER(15, R15D)
- NO_SUB_SUPER(16, R16D)
- NO_SUB_SUPER(17, R17D)
- NO_SUB_SUPER(18, R18D)
- NO_SUB_SUPER(19, R19D)
- NO_SUB_SUPER(20, R20D)
- NO_SUB_SUPER(21, R21D)
- NO_SUB_SUPER(22, R22D)
- NO_SUB_SUPER(23, R23D)
- NO_SUB_SUPER(24, R24D)
- NO_SUB_SUPER(25, R25D)
- NO_SUB_SUPER(26, R26D)
- NO_SUB_SUPER(27, R27D)
- NO_SUB_SUPER(28, R28D)
- NO_SUB_SUPER(29, R29D)
- NO_SUB_SUPER(30, R30D)
- NO_SUB_SUPER(31, R31D)
+ NO_SUB_SUPER_D(8)
+ NO_SUB_SUPER_D(9)
+ NO_SUB_SUPER_D(10)
+ NO_SUB_SUPER_D(11)
+ NO_SUB_SUPER_D(12)
+ NO_SUB_SUPER_D(13)
+ NO_SUB_SUPER_D(14)
+ NO_SUB_SUPER_D(15)
+ NO_SUB_SUPER_D(16)
+ NO_SUB_SUPER_D(17)
+ NO_SUB_SUPER_D(18)
+ NO_SUB_SUPER_D(19)
+ NO_SUB_SUPER_D(20)
+ NO_SUB_SUPER_D(21)
+ NO_SUB_SUPER_D(22)
+ NO_SUB_SUPER_D(23)
+ NO_SUB_SUPER_D(24)
+ NO_SUB_SUPER_D(25)
+ NO_SUB_SUPER_D(26)
+ NO_SUB_SUPER_D(27)
+ NO_SUB_SUPER_D(28)
+ NO_SUB_SUPER_D(29)
+ NO_SUB_SUPER_D(30)
+ NO_SUB_SUPER_D(31)
}
case 64:
switch (Reg.id()) {
@@ -918,30 +922,30 @@ MCRegister llvm::getX86SubSuperRegister(MCRegister Reg, unsigned Size,
DI_SUB_SUPER(RDI)
BP_SUB_SUPER(RBP)
SP_SUB_SUPER(RSP)
- NO_SUB_SUPER(8, R8)
- NO_SUB_SUPER(9, R9)
- NO_SUB_SUPER(10, R10)
- NO_SUB_SUPER(11, R11)
- NO_SUB_SUPER(12, R12)
- NO_SUB_SUPER(13, R13)
- NO_SUB_SUPER(14, R14)
- NO_SUB_SUPER(15, R15)
- NO_SUB_SUPER(16, R16)
- NO_SUB_SUPER(17, R17)
- NO_SUB_SUPER(18, R18)
- NO_SUB_SUPER(19, R19)
- NO_SUB_SUPER(20, R20)
- NO_SUB_SUPER(21, R21)
- NO_SUB_SUPER(22, R22)
- NO_SUB_SUPER(23, R23)
- NO_SUB_SUPER(24, R24)
- NO_SUB_SUPER(25, R25)
- NO_SUB_SUPER(26, R26)
- NO_SUB_SUPER(27, R27)
- NO_SUB_SUPER(28, R28)
- NO_SUB_SUPER(29, R29)
- NO_SUB_SUPER(30, R30)
- NO_SUB_SUPER(31, R31)
+ NO_SUB_SUPER_Q(8)
+ NO_SUB_SUPER_Q(9)
+ NO_SUB_SUPER_Q(10)
+ NO_SUB_SUPER_Q(11)
+ NO_SUB_SUPER_Q(12)
+ NO_SUB_SUPER_Q(13)
+ NO_SUB_SUPER_Q(14)
+ NO_SUB_SUPER_Q(15)
+ NO_SUB_SUPER_Q(16)
+ NO_SUB_SUPER_Q(17)
+ NO_SUB_SUPER_Q(18)
+ NO_SUB_SUPER_Q(19)
+ NO_SUB_SUPER_Q(20)
+ NO_SUB_SUPER_Q(21)
+ NO_SUB_SUPER_Q(22)
+ NO_SUB_SUPER_Q(23)
+ NO_SUB_SUPER_Q(24)
+ NO_SUB_SUPER_Q(25)
+ NO_SUB_SUPER_Q(26)
+ NO_SUB_SUPER_Q(27)
+ NO_SUB_SUPER_Q(28)
+ NO_SUB_SUPER_Q(29)
+ NO_SUB_SUPER_Q(30)
+ NO_SUB_SUPER_Q(31)
}
}
}
More information about the llvm-commits
mailing list