[llvm] [X86][NF] Switch the order of Inst and &Target.getInstruction(NewRec) (PR #130739)

Phoebe Wang via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 11 02:29:51 PDT 2025


https://github.com/phoebewang updated https://github.com/llvm/llvm-project/pull/130739

>From 56fe5ed37173dab0a48c0a25c7713937a54ccaa1 Mon Sep 17 00:00:00 2001
From: "Wang, Phoebe" <phoebe.wang at intel.com>
Date: Tue, 11 Mar 2025 17:18:38 +0800
Subject: [PATCH] [X86][NF] Switch the order of Inst and
 &Target.getInstruction(NewRec)

Because Inst is ordered by Instruction ID.
---
 llvm/test/TableGen/x86-instr-mapping.inc      | 48 +++++++++----------
 .../utils/TableGen/X86InstrMappingEmitter.cpp | 34 ++++++-------
 2 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/llvm/test/TableGen/x86-instr-mapping.inc b/llvm/test/TableGen/x86-instr-mapping.inc
index 4f64d4b8d93d0..1629e0eef93ec 100644
--- a/llvm/test/TableGen/x86-instr-mapping.inc
+++ b/llvm/test/TableGen/x86-instr-mapping.inc
@@ -1575,29 +1575,29 @@ static bool checkPredicate(unsigned Opc, const X86Subtarget *Subtarget) {
 
 #ifdef GET_X86_NF_TRANSFORM_TABLE
 static const X86TableEntry X86NFTransformTable[] = {
+  { X86::ADD16mi, X86::ADD16mi_NF },
   { X86::ADD16mi8, X86::ADD16mi8_NF },
   { X86::ADD16mi8_ND, X86::ADD16mi8_NF_ND },
-  { X86::ADD16mi, X86::ADD16mi_NF },
   { X86::ADD16mi_ND, X86::ADD16mi_NF_ND },
   { X86::ADD16mr, X86::ADD16mr_NF },
   { X86::ADD16mr_ND, X86::ADD16mr_NF_ND },
+  { X86::ADD16ri, X86::ADD16ri_NF },
   { X86::ADD16ri8, X86::ADD16ri8_NF },
   { X86::ADD16ri8_ND, X86::ADD16ri8_NF_ND },
-  { X86::ADD16ri, X86::ADD16ri_NF },
   { X86::ADD16ri_ND, X86::ADD16ri_NF_ND },
   { X86::ADD16rm, X86::ADD16rm_NF },
   { X86::ADD16rm_ND, X86::ADD16rm_NF_ND },
   { X86::ADD16rr, X86::ADD16rr_NF },
   { X86::ADD16rr_ND, X86::ADD16rr_NF_ND },
+  { X86::ADD32mi, X86::ADD32mi_NF },
   { X86::ADD32mi8, X86::ADD32mi8_NF },
   { X86::ADD32mi8_ND, X86::ADD32mi8_NF_ND },
-  { X86::ADD32mi, X86::ADD32mi_NF },
   { X86::ADD32mi_ND, X86::ADD32mi_NF_ND },
   { X86::ADD32mr, X86::ADD32mr_NF },
   { X86::ADD32mr_ND, X86::ADD32mr_NF_ND },
+  { X86::ADD32ri, X86::ADD32ri_NF },
   { X86::ADD32ri8, X86::ADD32ri8_NF },
   { X86::ADD32ri8_ND, X86::ADD32ri8_NF_ND },
-  { X86::ADD32ri, X86::ADD32ri_NF },
   { X86::ADD32ri_ND, X86::ADD32ri_NF_ND },
   { X86::ADD32rm, X86::ADD32rm_NF },
   { X86::ADD32rm_ND, X86::ADD32rm_NF_ND },
@@ -1627,29 +1627,29 @@ static const X86TableEntry X86NFTransformTable[] = {
   { X86::ADD8rm_ND, X86::ADD8rm_NF_ND },
   { X86::ADD8rr, X86::ADD8rr_NF },
   { X86::ADD8rr_ND, X86::ADD8rr_NF_ND },
+  { X86::AND16mi, X86::AND16mi_NF },
   { X86::AND16mi8, X86::AND16mi8_NF },
   { X86::AND16mi8_ND, X86::AND16mi8_NF_ND },
-  { X86::AND16mi, X86::AND16mi_NF },
   { X86::AND16mi_ND, X86::AND16mi_NF_ND },
   { X86::AND16mr, X86::AND16mr_NF },
   { X86::AND16mr_ND, X86::AND16mr_NF_ND },
+  { X86::AND16ri, X86::AND16ri_NF },
   { X86::AND16ri8, X86::AND16ri8_NF },
   { X86::AND16ri8_ND, X86::AND16ri8_NF_ND },
-  { X86::AND16ri, X86::AND16ri_NF },
   { X86::AND16ri_ND, X86::AND16ri_NF_ND },
   { X86::AND16rm, X86::AND16rm_NF },
   { X86::AND16rm_ND, X86::AND16rm_NF_ND },
   { X86::AND16rr, X86::AND16rr_NF },
   { X86::AND16rr_ND, X86::AND16rr_NF_ND },
+  { X86::AND32mi, X86::AND32mi_NF },
   { X86::AND32mi8, X86::AND32mi8_NF },
   { X86::AND32mi8_ND, X86::AND32mi8_NF_ND },
-  { X86::AND32mi, X86::AND32mi_NF },
   { X86::AND32mi_ND, X86::AND32mi_NF_ND },
   { X86::AND32mr, X86::AND32mr_NF },
   { X86::AND32mr_ND, X86::AND32mr_NF_ND },
+  { X86::AND32ri, X86::AND32ri_NF },
   { X86::AND32ri8, X86::AND32ri8_NF },
   { X86::AND32ri8_ND, X86::AND32ri8_NF_ND },
-  { X86::AND32ri, X86::AND32ri_NF },
   { X86::AND32ri_ND, X86::AND32ri_NF_ND },
   { X86::AND32rm, X86::AND32rm_NF },
   { X86::AND32rm_ND, X86::AND32rm_NF_ND },
@@ -1739,22 +1739,22 @@ static const X86TableEntry X86NFTransformTable[] = {
   { X86::IMUL16r, X86::IMUL16r_NF },
   { X86::IMUL16rm, X86::IMUL16rm_NF },
   { X86::IMUL16rm_ND, X86::IMUL16rm_NF_ND },
-  { X86::IMUL16rmi8, X86::IMUL16rmi8_NF },
   { X86::IMUL16rmi, X86::IMUL16rmi_NF },
+  { X86::IMUL16rmi8, X86::IMUL16rmi8_NF },
   { X86::IMUL16rr, X86::IMUL16rr_NF },
   { X86::IMUL16rr_ND, X86::IMUL16rr_NF_ND },
-  { X86::IMUL16rri8, X86::IMUL16rri8_NF },
   { X86::IMUL16rri, X86::IMUL16rri_NF },
+  { X86::IMUL16rri8, X86::IMUL16rri8_NF },
   { X86::IMUL32m, X86::IMUL32m_NF },
   { X86::IMUL32r, X86::IMUL32r_NF },
   { X86::IMUL32rm, X86::IMUL32rm_NF },
   { X86::IMUL32rm_ND, X86::IMUL32rm_NF_ND },
-  { X86::IMUL32rmi8, X86::IMUL32rmi8_NF },
   { X86::IMUL32rmi, X86::IMUL32rmi_NF },
+  { X86::IMUL32rmi8, X86::IMUL32rmi8_NF },
   { X86::IMUL32rr, X86::IMUL32rr_NF },
   { X86::IMUL32rr_ND, X86::IMUL32rr_NF_ND },
-  { X86::IMUL32rri8, X86::IMUL32rri8_NF },
   { X86::IMUL32rri, X86::IMUL32rri_NF },
+  { X86::IMUL32rri8, X86::IMUL32rri8_NF },
   { X86::IMUL64m, X86::IMUL64m_NF },
   { X86::IMUL64r, X86::IMUL64r_NF },
   { X86::IMUL64rm, X86::IMUL64rm_NF },
@@ -1813,29 +1813,29 @@ static const X86TableEntry X86NFTransformTable[] = {
   { X86::NEG8m_ND, X86::NEG8m_NF_ND },
   { X86::NEG8r, X86::NEG8r_NF },
   { X86::NEG8r_ND, X86::NEG8r_NF_ND },
+  { X86::OR16mi, X86::OR16mi_NF },
   { X86::OR16mi8, X86::OR16mi8_NF },
   { X86::OR16mi8_ND, X86::OR16mi8_NF_ND },
-  { X86::OR16mi, X86::OR16mi_NF },
   { X86::OR16mi_ND, X86::OR16mi_NF_ND },
   { X86::OR16mr, X86::OR16mr_NF },
   { X86::OR16mr_ND, X86::OR16mr_NF_ND },
+  { X86::OR16ri, X86::OR16ri_NF },
   { X86::OR16ri8, X86::OR16ri8_NF },
   { X86::OR16ri8_ND, X86::OR16ri8_NF_ND },
-  { X86::OR16ri, X86::OR16ri_NF },
   { X86::OR16ri_ND, X86::OR16ri_NF_ND },
   { X86::OR16rm, X86::OR16rm_NF },
   { X86::OR16rm_ND, X86::OR16rm_NF_ND },
   { X86::OR16rr, X86::OR16rr_NF },
   { X86::OR16rr_ND, X86::OR16rr_NF_ND },
+  { X86::OR32mi, X86::OR32mi_NF },
   { X86::OR32mi8, X86::OR32mi8_NF },
   { X86::OR32mi8_ND, X86::OR32mi8_NF_ND },
-  { X86::OR32mi, X86::OR32mi_NF },
   { X86::OR32mi_ND, X86::OR32mi_NF_ND },
   { X86::OR32mr, X86::OR32mr_NF },
   { X86::OR32mr_ND, X86::OR32mr_NF_ND },
+  { X86::OR32ri, X86::OR32ri_NF },
   { X86::OR32ri8, X86::OR32ri8_NF },
   { X86::OR32ri8_ND, X86::OR32ri8_NF_ND },
-  { X86::OR32ri, X86::OR32ri_NF },
   { X86::OR32ri_ND, X86::OR32ri_NF_ND },
   { X86::OR32rm, X86::OR32rm_NF },
   { X86::OR32rm_ND, X86::OR32rm_NF_ND },
@@ -2159,29 +2159,29 @@ static const X86TableEntry X86NFTransformTable[] = {
   { X86::SHRD64rrCL_ND, X86::SHRD64rrCL_NF_ND },
   { X86::SHRD64rri8, X86::SHRD64rri8_NF },
   { X86::SHRD64rri8_ND, X86::SHRD64rri8_NF_ND },
+  { X86::SUB16mi, X86::SUB16mi_NF },
   { X86::SUB16mi8, X86::SUB16mi8_NF },
   { X86::SUB16mi8_ND, X86::SUB16mi8_NF_ND },
-  { X86::SUB16mi, X86::SUB16mi_NF },
   { X86::SUB16mi_ND, X86::SUB16mi_NF_ND },
   { X86::SUB16mr, X86::SUB16mr_NF },
   { X86::SUB16mr_ND, X86::SUB16mr_NF_ND },
+  { X86::SUB16ri, X86::SUB16ri_NF },
   { X86::SUB16ri8, X86::SUB16ri8_NF },
   { X86::SUB16ri8_ND, X86::SUB16ri8_NF_ND },
-  { X86::SUB16ri, X86::SUB16ri_NF },
   { X86::SUB16ri_ND, X86::SUB16ri_NF_ND },
   { X86::SUB16rm, X86::SUB16rm_NF },
   { X86::SUB16rm_ND, X86::SUB16rm_NF_ND },
   { X86::SUB16rr, X86::SUB16rr_NF },
   { X86::SUB16rr_ND, X86::SUB16rr_NF_ND },
+  { X86::SUB32mi, X86::SUB32mi_NF },
   { X86::SUB32mi8, X86::SUB32mi8_NF },
   { X86::SUB32mi8_ND, X86::SUB32mi8_NF_ND },
-  { X86::SUB32mi, X86::SUB32mi_NF },
   { X86::SUB32mi_ND, X86::SUB32mi_NF_ND },
   { X86::SUB32mr, X86::SUB32mr_NF },
   { X86::SUB32mr_ND, X86::SUB32mr_NF_ND },
+  { X86::SUB32ri, X86::SUB32ri_NF },
   { X86::SUB32ri8, X86::SUB32ri8_NF },
   { X86::SUB32ri8_ND, X86::SUB32ri8_NF_ND },
-  { X86::SUB32ri, X86::SUB32ri_NF },
   { X86::SUB32ri_ND, X86::SUB32ri_NF_ND },
   { X86::SUB32rm, X86::SUB32rm_NF },
   { X86::SUB32rm_ND, X86::SUB32rm_NF_ND },
@@ -2217,29 +2217,29 @@ static const X86TableEntry X86NFTransformTable[] = {
   { X86::TZCNT32rr, X86::TZCNT32rr_NF },
   { X86::TZCNT64rm, X86::TZCNT64rm_NF },
   { X86::TZCNT64rr, X86::TZCNT64rr_NF },
+  { X86::XOR16mi, X86::XOR16mi_NF },
   { X86::XOR16mi8, X86::XOR16mi8_NF },
   { X86::XOR16mi8_ND, X86::XOR16mi8_NF_ND },
-  { X86::XOR16mi, X86::XOR16mi_NF },
   { X86::XOR16mi_ND, X86::XOR16mi_NF_ND },
   { X86::XOR16mr, X86::XOR16mr_NF },
   { X86::XOR16mr_ND, X86::XOR16mr_NF_ND },
+  { X86::XOR16ri, X86::XOR16ri_NF },
   { X86::XOR16ri8, X86::XOR16ri8_NF },
   { X86::XOR16ri8_ND, X86::XOR16ri8_NF_ND },
-  { X86::XOR16ri, X86::XOR16ri_NF },
   { X86::XOR16ri_ND, X86::XOR16ri_NF_ND },
   { X86::XOR16rm, X86::XOR16rm_NF },
   { X86::XOR16rm_ND, X86::XOR16rm_NF_ND },
   { X86::XOR16rr, X86::XOR16rr_NF },
   { X86::XOR16rr_ND, X86::XOR16rr_NF_ND },
+  { X86::XOR32mi, X86::XOR32mi_NF },
   { X86::XOR32mi8, X86::XOR32mi8_NF },
   { X86::XOR32mi8_ND, X86::XOR32mi8_NF_ND },
-  { X86::XOR32mi, X86::XOR32mi_NF },
   { X86::XOR32mi_ND, X86::XOR32mi_NF_ND },
   { X86::XOR32mr, X86::XOR32mr_NF },
   { X86::XOR32mr_ND, X86::XOR32mr_NF_ND },
+  { X86::XOR32ri, X86::XOR32ri_NF },
   { X86::XOR32ri8, X86::XOR32ri8_NF },
   { X86::XOR32ri8_ND, X86::XOR32ri8_NF_ND },
-  { X86::XOR32ri, X86::XOR32ri_NF },
   { X86::XOR32ri_ND, X86::XOR32ri_NF_ND },
   { X86::XOR32rm, X86::XOR32rm_NF },
   { X86::XOR32rm_ND, X86::XOR32rm_NF_ND },
diff --git a/llvm/utils/TableGen/X86InstrMappingEmitter.cpp b/llvm/utils/TableGen/X86InstrMappingEmitter.cpp
index df43f39e0e9be..0ba0a0dd50888 100644
--- a/llvm/utils/TableGen/X86InstrMappingEmitter.cpp
+++ b/llvm/utils/TableGen/X86InstrMappingEmitter.cpp
@@ -275,27 +275,27 @@ void X86InstrMappingEmitter::emitNFTransformTable(
     const Record *Rec = Inst->TheDef;
     if (!isInteresting(Rec))
       continue;
-    std::string Name = Rec->getName().str();
-    auto Pos = Name.find("_NF");
-    if (Pos == std::string::npos)
+    StringRef Name = Rec->getName();
+    auto *NewRec = Records.getDef(Name.str() + "_NF");
+    if (!NewRec && Name.consume_back("_ND"))
+      NewRec = Records.getDef(Name.str() + "_NF_ND");
+
+    if (!NewRec)
       continue;
 
-    if (auto *NewRec = Records.getDef(Name.erase(Pos, 3))) {
 #ifndef NDEBUG
-      auto ClobberEFLAGS = [](const Record *R) {
-        return llvm::any_of(
-            R->getValueAsListOfDefs("Defs"),
-            [](const Record *Def) { return Def->getName() == "EFLAGS"; });
-      };
-      if (ClobberEFLAGS(Rec))
-        report_fatal_error("EFLAGS should not be clobbered by " +
-                           Rec->getName());
-      if (!ClobberEFLAGS(NewRec))
-        report_fatal_error("EFLAGS should be clobbered by " +
-                           NewRec->getName());
+    auto ClobberEFLAGS = [](const Record *R) {
+      return llvm::any_of(
+          R->getValueAsListOfDefs("Defs"),
+          [](const Record *Def) { return Def->getName() == "EFLAGS"; });
+    };
+    if (ClobberEFLAGS(NewRec))
+      report_fatal_error("EFLAGS should not be clobbered by " +
+                         NewRec->getName());
+    if (!ClobberEFLAGS(Rec))
+      report_fatal_error("EFLAGS should be clobbered by " + Rec->getName());
 #endif
-      Table.emplace_back(&Target.getInstruction(NewRec), Inst);
-    }
+    Table.emplace_back(Inst, &Target.getInstruction(NewRec));
   }
   printTable(Table, "X86NFTransformTable", "GET_X86_NF_TRANSFORM_TABLE", OS);
 }



More information about the llvm-commits mailing list