[llvm] [X86][MC] Teach disassembler to recognize apx instructions which ignores W bit (PR #82747)

via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 26 22:14:54 PST 2024


https://github.com/XinWang10 updated https://github.com/llvm/llvm-project/pull/82747

>From 9627e57f57f07da51d55cf248a08cabea73ffa4b Mon Sep 17 00:00:00 2001
From: "Wang, Xin10" <xin10.wang at intel.com>
Date: Fri, 23 Feb 2024 01:48:46 -0800
Subject: [PATCH 1/3] [X86][MC] Teach disassembler to recognize apx
 instructions which ignores W bit

---
 llvm/lib/Target/X86/X86InstrSystem.td         |  2 +-
 llvm/lib/Target/X86/X86InstrUtils.td          |  1 +
 llvm/lib/Target/X86/X86InstrVMX.td            |  4 +-
 llvm/test/MC/Disassembler/X86/apx/IgnoreW.txt | 98 +++++++++++++++++++
 llvm/utils/TableGen/X86DisassemblerTables.cpp |  2 +
 5 files changed, 104 insertions(+), 3 deletions(-)
 create mode 100644 llvm/test/MC/Disassembler/X86/apx/IgnoreW.txt

diff --git a/llvm/lib/Target/X86/X86InstrSystem.td b/llvm/lib/Target/X86/X86InstrSystem.td
index d051047ae46548..56293e20567ed1 100644
--- a/llvm/lib/Target/X86/X86InstrSystem.td
+++ b/llvm/lib/Target/X86/X86InstrSystem.td
@@ -716,7 +716,7 @@ def INVPCID64 : I<0x82, MRMSrcMem, (outs), (ins GR64:$src1, i128mem:$src2),
 
 def INVPCID64_EVEX : I<0xF2, MRMSrcMem, (outs), (ins GR64:$src1, i128mem:$src2),
                        "invpcid\t{$src2, $src1|$src1, $src2}", []>,
-                     EVEX, NoCD8, T_MAP4, XS, Requires<[In64BitMode]>;
+                     EVEX, NoCD8, T_MAP4, XS, WIG, Requires<[In64BitMode]>;
 } // SchedRW
 
 let Predicates = [HasINVPCID, NoEGPR] in {
diff --git a/llvm/lib/Target/X86/X86InstrUtils.td b/llvm/lib/Target/X86/X86InstrUtils.td
index 05ddcfbf2726d9..04d9d104ebc4b0 100644
--- a/llvm/lib/Target/X86/X86InstrUtils.td
+++ b/llvm/lib/Target/X86/X86InstrUtils.td
@@ -967,6 +967,7 @@ class ITy<bits<8> o, Format f, X86TypeInfo t, dag outs, dag ins, string m,
       !strconcat(m, "{", t.InstrSuffix, "}\t", args), p>, NoCD8 {
   let hasSideEffects = 0;
   let hasREX_W  = t.HasREX_W;
+  let IgnoresW = !if(!eq(t.VT, i8), 1, 0);
 }
 
 // BinOpRR - Instructions that read "reg, reg".
diff --git a/llvm/lib/Target/X86/X86InstrVMX.td b/llvm/lib/Target/X86/X86InstrVMX.td
index 7cc468fe15ad4e..da2b3d76a130cf 100644
--- a/llvm/lib/Target/X86/X86InstrVMX.td
+++ b/llvm/lib/Target/X86/X86InstrVMX.td
@@ -24,7 +24,7 @@ def INVEPT64 : I<0x80, MRMSrcMem, (outs), (ins GR64:$src1, i128mem:$src2),
                Requires<[In64BitMode]>;
 def INVEPT64_EVEX : I<0xF0, MRMSrcMem, (outs), (ins GR64:$src1, i128mem:$src2),
                       "invept\t{$src2, $src1|$src1, $src2}", []>,
-                    EVEX, NoCD8, T_MAP4, XS, Requires<[In64BitMode]>;
+                    EVEX, NoCD8, T_MAP4, XS, WIG, Requires<[In64BitMode]>;
 
 // 66 0F 38 81
 def INVVPID32 : I<0x81, MRMSrcMem, (outs), (ins GR32:$src1, i128mem:$src2),
@@ -35,7 +35,7 @@ def INVVPID64 : I<0x81, MRMSrcMem, (outs), (ins GR64:$src1, i128mem:$src2),
                 Requires<[In64BitMode]>;
 def INVVPID64_EVEX : I<0xF1, MRMSrcMem, (outs), (ins GR64:$src1, i128mem:$src2),
                        "invvpid\t{$src2, $src1|$src1, $src2}", []>,
-                     EVEX, NoCD8, T_MAP4, XS, Requires<[In64BitMode]>;
+                     EVEX, NoCD8, T_MAP4, XS, WIG, Requires<[In64BitMode]>;
 
 // 0F 01 C1
 def VMCALL : I<0x01, MRM_C1, (outs), (ins), "vmcall", []>, TB;
diff --git a/llvm/test/MC/Disassembler/X86/apx/IgnoreW.txt b/llvm/test/MC/Disassembler/X86/apx/IgnoreW.txt
new file mode 100644
index 00000000000000..96db156ae1d181
--- /dev/null
+++ b/llvm/test/MC/Disassembler/X86/apx/IgnoreW.txt
@@ -0,0 +1,98 @@
+# RUN: llvm-mc --disassemble %s -triple=x86_64 | FileCheck %s --check-prefixes=ATT
+# RUN: llvm-mc --disassemble %s -triple=x86_64 -x86-asm-syntax=intel --output-asm-variant=1 | FileCheck %s --check-prefixes=INTEL
+
+## invpcid
+
+# ATT:   invpcid	123(%rax,%rbx,4), %r9
+# INTEL: invpcid	r9, xmmword ptr [rax + 4*rbx + 123]
+0x62,0x74,0xfe,0x08,0xf2,0x4c,0x98,0x7b
+
+# ATT:   invpcid	291(%r28,%r29,4), %r19
+# INTEL: invpcid	r19, xmmword ptr [r28 + 4*r29 + 291]
+0x62,0x8c,0xfa,0x08,0xf2,0x9c,0xac,0x23,0x01,0x00,0x00
+
+## invept
+
+# ATT:   invept	291(%r28,%r29,4), %r19
+# INTEL: invept	r19, xmmword ptr [r28 + 4*r29 + 291]
+0x62,0x8c,0xfa,0x08,0xf0,0x9c,0xac,0x23,0x01,0x00,0x00
+
+# ATT:   invept	123(%rax,%rbx,4), %r9
+# INTEL: invept	r9, xmmword ptr [rax + 4*rbx + 123]
+0x62,0x74,0xfe,0x08,0xf0,0x4c,0x98,0x7b
+
+## invvpid
+
+# ATT:   invvpid	291(%r28,%r29,4), %r19
+# INTEL: invvpid	r19, xmmword ptr [r28 + 4*r29 + 291]
+0x62,0x8c,0xfa,0x08,0xf1,0x9c,0xac,0x23,0x01,0x00,0x00
+
+# ATT:   invvpid	123(%rax,%rbx,4), %r9
+# INTEL: invvpid	r9, xmmword ptr [rax + 4*rbx + 123]
+0x62,0x74,0xfe,0x08,0xf1,0x4c,0x98,0x7b
+
+## adc
+
+# ATT:   {evex}	adcb	$123, %bl
+# INTEL: {evex}	adc	bl, 123
+0x62,0xf4,0xfc,0x08,0x80,0xd3,0x7b
+
+# ATT:   adcb	$123, %bl, %cl
+# INTEL: adc	cl, bl, 123
+0x62,0xf4,0xf4,0x18,0x80,0xd3,0x7b
+
+## add
+
+# ATT:   {evex}	addb	$123, %bl
+# INTEL: {evex}	add	bl, 123
+0x62,0xf4,0xfc,0x08,0x80,0xc3,0x7b
+
+# ATT:   {nf}	addb	$123, %bl
+# INTEL: {nf}	add	bl, 123
+0x62,0xf4,0xfc,0x0c,0x80,0xc3,0x7b
+
+# ATT:   addb	$123, %bl, %cl
+# INTEL: add	cl, bl, 123
+0x62,0xf4,0xf4,0x18,0x80,0xc3,0x7b
+
+# ATT:   {nf}	addb	$123, %bl, %cl
+# INTEL: {nf}	add	cl, bl, 123
+0x62,0xf4,0xf4,0x1c,0x80,0xc3,0x7b
+
+## inc
+
+# ATT:   {evex}	incb	%bl
+# INTEL: {evex}	inc	bl
+0x62,0xf4,0xfc,0x08,0xfe,0xc3
+
+# ATT:   {nf}	incb	%bl
+# INTEL: {nf}	inc	bl
+0x62,0xf4,0xfc,0x0c,0xfe,0xc3
+
+# ATT:   incb	%bl, %bl
+# INTEL: inc	bl, bl
+0x62,0xf4,0xe4,0x18,0xfe,0xc3
+
+# ATT:   {nf}	incb	%bl, %bl
+# INTEL: {nf}	inc	bl, bl
+0x62,0xf4,0xe4,0x1c,0xfe,0xc3
+
+## mul
+
+# ATT:   {evex}	mulb	%bl
+# INTEL: {evex}	mul	bl
+0x62,0xf4,0xfc,0x08,0xf6,0xe3
+
+# ATT:   {nf}	mulb	%bl
+# INTEL: {nf}	mul	bl
+0x62,0xf4,0xfc,0x0c,0xf6,0xe3
+
+## imul
+
+# ATT:   {evex}	imulb	%bl
+# INTEL: {evex}	imul	bl
+0x62,0xf4,0xfc,0x08,0xf6,0xeb
+
+# ATT:   {nf}	imulb	%bl
+# INTEL: {nf}	imul	bl
+0x62,0xf4,0xfc,0x0c,0xf6,0xeb
diff --git a/llvm/utils/TableGen/X86DisassemblerTables.cpp b/llvm/utils/TableGen/X86DisassemblerTables.cpp
index a48b9cfe42e37f..f4d282f54ac055 100644
--- a/llvm/utils/TableGen/X86DisassemblerTables.cpp
+++ b/llvm/utils/TableGen/X86DisassemblerTables.cpp
@@ -567,7 +567,9 @@ static inline bool inheritsFrom(InstructionContext child,
   case IC_EVEX_L2_W_OPSIZE_KZ_B:
     return false;
   case IC_EVEX_NF:
+    return WIG && inheritsFrom(child, IC_EVEX_W_NF);
   case IC_EVEX_B_NF:
+    return WIG && inheritsFrom(child, IC_EVEX_W_B_NF);
   case IC_EVEX_OPSIZE_NF:
   case IC_EVEX_OPSIZE_B_NF:
   case IC_EVEX_W_NF:

>From e2745aab5dbd6dae4044b8f2674e47e52503c878 Mon Sep 17 00:00:00 2001
From: "Wang, Xin10" <xin10.wang at intel.com>
Date: Mon, 26 Feb 2024 19:25:06 -0800
Subject: [PATCH 2/3] Add test for Rex2 prefix

---
 llvm/test/MC/Disassembler/X86/apx/IgnoreW.txt | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/llvm/test/MC/Disassembler/X86/apx/IgnoreW.txt b/llvm/test/MC/Disassembler/X86/apx/IgnoreW.txt
index 96db156ae1d181..a09b5fecc890f8 100644
--- a/llvm/test/MC/Disassembler/X86/apx/IgnoreW.txt
+++ b/llvm/test/MC/Disassembler/X86/apx/IgnoreW.txt
@@ -41,6 +41,10 @@
 # INTEL: adc	cl, bl, 123
 0x62,0xf4,0xf4,0x18,0x80,0xd3,0x7b
 
+# ATT:   adcb	$123, %r16b
+# INTEL: adc	r16b, 123
+0xd5,0x18,0x80,0xd0,0x7b
+
 ## add
 
 # ATT:   {evex}	addb	$123, %bl
@@ -59,6 +63,10 @@
 # INTEL: {nf}	add	cl, bl, 123
 0x62,0xf4,0xf4,0x1c,0x80,0xc3,0x7b
 
+# ATT:   addb	$123, %r16b
+# INTEL: add	r16b, 123
+0xd5,0x10,0x80,0xc0,0x7b
+
 ## inc
 
 # ATT:   {evex}	incb	%bl
@@ -77,6 +85,10 @@
 # INTEL: {nf}	inc	bl, bl
 0x62,0xf4,0xe4,0x1c,0xfe,0xc3
 
+# ATT:   incb	%r16b
+# INTEL: inc	r16b
+0xd5,0x10,0xfe,0xc0
+
 ## mul
 
 # ATT:   {evex}	mulb	%bl
@@ -87,6 +99,10 @@
 # INTEL: {nf}	mul	bl
 0x62,0xf4,0xfc,0x0c,0xf6,0xe3
 
+# ATT:   mulb	%r16b
+# INTEL: mul	r16b
+0xd5,0x10,0xf6,0xe0
+
 ## imul
 
 # ATT:   {evex}	imulb	%bl
@@ -96,3 +112,7 @@
 # ATT:   {nf}	imulb	%bl
 # INTEL: {nf}	imul	bl
 0x62,0xf4,0xfc,0x0c,0xf6,0xeb
+
+# ATT:   imulb	%r16b
+# INTEL: imul	r16b
+0xd5,0x10,0xf6,0xe8

>From 73c2d7478c318b8f9acfcec2ef0fef3bff11c01a Mon Sep 17 00:00:00 2001
From: "Wang, Xin10" <xin10.wang at intel.com>
Date: Mon, 26 Feb 2024 22:14:41 -0800
Subject: [PATCH 3/3] update test

---
 llvm/test/MC/Disassembler/X86/apx/IgnoreW.txt | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/test/MC/Disassembler/X86/apx/IgnoreW.txt b/llvm/test/MC/Disassembler/X86/apx/IgnoreW.txt
index a09b5fecc890f8..df41bdf39fd61b 100644
--- a/llvm/test/MC/Disassembler/X86/apx/IgnoreW.txt
+++ b/llvm/test/MC/Disassembler/X86/apx/IgnoreW.txt
@@ -65,7 +65,7 @@
 
 # ATT:   addb	$123, %r16b
 # INTEL: add	r16b, 123
-0xd5,0x10,0x80,0xc0,0x7b
+0xd5,0x18,0x80,0xc0,0x7b
 
 ## inc
 
@@ -87,7 +87,7 @@
 
 # ATT:   incb	%r16b
 # INTEL: inc	r16b
-0xd5,0x10,0xfe,0xc0
+0xd5,0x18,0xfe,0xc0
 
 ## mul
 
@@ -101,7 +101,7 @@
 
 # ATT:   mulb	%r16b
 # INTEL: mul	r16b
-0xd5,0x10,0xf6,0xe0
+0xd5,0x18,0xf6,0xe0
 
 ## imul
 
@@ -115,4 +115,4 @@
 
 # ATT:   imulb	%r16b
 # INTEL: imul	r16b
-0xd5,0x10,0xf6,0xe8
+0xd5,0x18,0xf6,0xe8



More information about the llvm-commits mailing list