[llvm] [X86][MC] Error out for CMPCCXADD on 32 bit targets. (PR #88672)

Freddy Ye via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 18 23:23:36 PDT 2024


https://github.com/FreddyLeaf updated https://github.com/llvm/llvm-project/pull/88672

>From 654704b35ee2589f5f62926d17a97fc70d9fefea Mon Sep 17 00:00:00 2001
From: Freddy Ye <freddy.ye at intel.com>
Date: Mon, 15 Apr 2024 09:24:47 +0800
Subject: [PATCH 1/2] [X86][MC] Error out for CMPCCXADD on 32 bit targets.

This resolves issue #88501.
---
 llvm/lib/Target/X86/X86InstrAsmAlias.td | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/llvm/lib/Target/X86/X86InstrAsmAlias.td b/llvm/lib/Target/X86/X86InstrAsmAlias.td
index d06a0c79b46bbb..fbe95794a209f6 100644
--- a/llvm/lib/Target/X86/X86InstrAsmAlias.td
+++ b/llvm/lib/Target/X86/X86InstrAsmAlias.td
@@ -51,15 +51,17 @@ def : InstAlias<"invlpgb\t{%rax, %edx|rax, edx}", (INVLPGB64)>, Requires<[In64Bi
 
 // CMPCCXADD Instructions Alias
 multiclass CMPCCXADD_Aliases<string Cond, int CC> {
-  def : InstAlias<"cmp"#Cond#"xadd"#"\t{$src3, $dst, $dstsrc2|$dstsrc2, $dst, $src3}",
-                  (CMPCCXADDmr32 GR32:$dst, i32mem:$dstsrc2, GR32:$src3, CC), 0>;
-  def : InstAlias<"cmp"#Cond#"xadd"#"\t{$src3, $dst, $dstsrc2|$dstsrc2, $dst, $src3}",
-                  (CMPCCXADDmr64 GR64:$dst, i64mem:$dstsrc2, GR64:$src3, CC), 0>;
-
-  def : InstAlias<"cmp"#Cond#"xadd"#"\t{$src3, $dst, $dstsrc2|$dstsrc2, $dst, $src3}",
-                  (CMPCCXADDmr32_EVEX GR32:$dst, i32mem:$dstsrc2, GR32:$src3, CC), 0>;
-  def : InstAlias<"cmp"#Cond#"xadd"#"\t{$src3, $dst, $dstsrc2|$dstsrc2, $dst, $src3}",
-                  (CMPCCXADDmr64_EVEX GR64:$dst, i64mem:$dstsrc2, GR64:$src3, CC), 0>;
+  let Predicates = [In64BitMode] in {
+    def : InstAlias<"cmp"#Cond#"xadd"#"\t{$src3, $dst, $dstsrc2|$dstsrc2, $dst, $src3}",
+                    (CMPCCXADDmr32 GR32:$dst, i32mem:$dstsrc2, GR32:$src3, CC), 0>;
+    def : InstAlias<"cmp"#Cond#"xadd"#"\t{$src3, $dst, $dstsrc2|$dstsrc2, $dst, $src3}",
+                    (CMPCCXADDmr64 GR64:$dst, i64mem:$dstsrc2, GR64:$src3, CC), 0>;
+
+    def : InstAlias<"cmp"#Cond#"xadd"#"\t{$src3, $dst, $dstsrc2|$dstsrc2, $dst, $src3}",
+                    (CMPCCXADDmr32_EVEX GR32:$dst, i32mem:$dstsrc2, GR32:$src3, CC), 0>;
+    def : InstAlias<"cmp"#Cond#"xadd"#"\t{$src3, $dst, $dstsrc2|$dstsrc2, $dst, $src3}",
+                    (CMPCCXADDmr64_EVEX GR64:$dst, i64mem:$dstsrc2, GR64:$src3, CC), 0>;
+  }
 }
 
 // CCMP Instructions Alias

>From 14d15d7a0f3587cd02aeba48c5460df1445ae3de Mon Sep 17 00:00:00 2001
From: Freddy Ye <freddy.ye at intel.com>
Date: Fri, 19 Apr 2024 14:21:23 +0800
Subject: [PATCH 2/2] add test

---
 llvm/test/MC/X86/apx/cmpccxadd-att.s                   |  6 +++---
 ...{cmpccxadd-att-64-alias.s => cmpccxadd-att-alias.s} |  0
 .../MC/X86/{cmpccxadd-att-64.s => cmpccxadd-att.s}     | 10 +++++++---
 ...ccxadd-intel-64-alias.s => cmpccxadd-intel-alias.s} |  0
 .../MC/X86/{cmpccxadd-intel-64.s => cmpccxadd-intel.s} |  0
 5 files changed, 10 insertions(+), 6 deletions(-)
 rename llvm/test/MC/X86/{cmpccxadd-att-64-alias.s => cmpccxadd-att-alias.s} (100%)
 rename llvm/test/MC/X86/{cmpccxadd-att-64.s => cmpccxadd-att.s} (99%)
 rename llvm/test/MC/X86/{cmpccxadd-intel-64-alias.s => cmpccxadd-intel-alias.s} (100%)
 rename llvm/test/MC/X86/{cmpccxadd-intel-64.s => cmpccxadd-intel.s} (100%)

diff --git a/llvm/test/MC/X86/apx/cmpccxadd-att.s b/llvm/test/MC/X86/apx/cmpccxadd-att.s
index 0a21abbd0ed250..d6ade869ca1d26 100644
--- a/llvm/test/MC/X86/apx/cmpccxadd-att.s
+++ b/llvm/test/MC/X86/apx/cmpccxadd-att.s
@@ -3,9 +3,9 @@
 
 # ERROR-COUNT-60: error:
 # ERROR-NOT: error:
-# CHECK: {evex}	cmpnbexadd	%ecx, %edx, 123(%rax,%rbx,4)
-# CHECK: encoding: [0x62,0xf2,0x75,0x08,0xe7,0x54,0x98,0x7b]
-         {evex}	cmpnbexadd	%ecx, %edx, 123(%rax,%rbx,4)
+# CHECK: {evex}	cmpnbexadd	%ecx, %edx, 123(%eax,%ebx,4)
+# CHECK: encoding: [0x67,0x62,0xf2,0x75,0x08,0xe7,0x54,0x98,0x7b]
+         {evex}	cmpnbexadd	%ecx, %edx, 123(%eax,%ebx,4)
 
 # CHECK: {evex}	cmpnbexadd	%r9, %r15, 123(%rax,%rbx,4)
 # CHECK: encoding: [0x62,0x72,0xb5,0x08,0xe7,0x7c,0x98,0x7b]
diff --git a/llvm/test/MC/X86/cmpccxadd-att-64-alias.s b/llvm/test/MC/X86/cmpccxadd-att-alias.s
similarity index 100%
rename from llvm/test/MC/X86/cmpccxadd-att-64-alias.s
rename to llvm/test/MC/X86/cmpccxadd-att-alias.s
diff --git a/llvm/test/MC/X86/cmpccxadd-att-64.s b/llvm/test/MC/X86/cmpccxadd-att.s
similarity index 99%
rename from llvm/test/MC/X86/cmpccxadd-att-64.s
rename to llvm/test/MC/X86/cmpccxadd-att.s
index 2ef49cba92e32c..c79cc55a15b81d 100644
--- a/llvm/test/MC/X86/cmpccxadd-att-64.s
+++ b/llvm/test/MC/X86/cmpccxadd-att.s
@@ -1,4 +1,8 @@
 // RUN: llvm-mc -triple x86_64 --show-encoding %s | FileCheck %s
+// RUN: not llvm-mc -triple i386 -show-encoding %s 2>&1 | FileCheck %s --check-prefix=ERROR
+
+// ERROR-COUNT-193: error:
+// ERROR-NOT: error:
 
 // CHECK: cmpbexadd  %eax, %ecx, 268435456(%rbp,%r14,8)
 // CHECK: encoding: [0xc4,0xa2,0x79,0xe6,0x8c,0xf5,0x00,0x00,0x00,0x10]
@@ -20,9 +24,9 @@
 // CHECK: encoding: [0xc4,0xe2,0x79,0xe6,0x89,0xfc,0x01,0x00,0x00]
           cmpbexadd  %eax, %ecx, 508(%rcx)
 
-// CHECK: cmpbexadd  %eax, %ecx, -512(%rdx)
-// CHECK: encoding: [0xc4,0xe2,0x79,0xe6,0x8a,0x00,0xfe,0xff,0xff]
-          cmpbexadd  %eax, %ecx, -512(%rdx)
+// CHECK: cmpbexadd  %eax, %ecx, -512(%edx)
+// CHECK: encoding: [0x67,0xc4,0xe2,0x79,0xe6,0x8a,0x00,0xfe,0xff,0xff]
+          cmpbexadd  %eax, %ecx, -512(%edx)
 
 // CHECK: cmpbexadd  %r10, %r9, 268435456(%rbp,%r14,8)
 // CHECK: encoding: [0xc4,0x22,0xa9,0xe6,0x8c,0xf5,0x00,0x00,0x00,0x10]
diff --git a/llvm/test/MC/X86/cmpccxadd-intel-64-alias.s b/llvm/test/MC/X86/cmpccxadd-intel-alias.s
similarity index 100%
rename from llvm/test/MC/X86/cmpccxadd-intel-64-alias.s
rename to llvm/test/MC/X86/cmpccxadd-intel-alias.s
diff --git a/llvm/test/MC/X86/cmpccxadd-intel-64.s b/llvm/test/MC/X86/cmpccxadd-intel.s
similarity index 100%
rename from llvm/test/MC/X86/cmpccxadd-intel-64.s
rename to llvm/test/MC/X86/cmpccxadd-intel.s



More information about the llvm-commits mailing list