[llvm] 7cd3268 - [X86][TableGen] Fix the mnemonic table for CMPCCXADD

Shengchen Kan via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 4 20:31:37 PST 2024


Author: Shengchen Kan
Date: 2024-03-05T12:30:55+08:00
New Revision: 7cd32688042988d2d02f791dd106286a67041b63

URL: https://github.com/llvm/llvm-project/commit/7cd32688042988d2d02f791dd106286a67041b63
DIFF: https://github.com/llvm/llvm-project/commit/7cd32688042988d2d02f791dd106286a67041b63.diff

LOG: [X86][TableGen] Fix the mnemonic table for CMPCCXADD

The mnemonic of CMPCCXADD is `cmp${cond}xadd` and the condition code
is in the middle of mnemonic. When generating the function name for
CMPCCXADD, the substring `xadd` should be kept.

Before this patch, the name is `isCMPCC`. After this patch, the name
is `isCMPCCXADD`.

Added: 
    

Modified: 
    llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.cpp
    llvm/utils/TableGen/X86RecognizableInstr.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.cpp
index e519c00a21109a..7422a989734653 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86InstPrinterCommon.cpp
@@ -29,29 +29,29 @@ using namespace llvm;
 void X86InstPrinterCommon::printCondCode(const MCInst *MI, unsigned Op,
                                          raw_ostream &O) {
   int64_t Imm = MI->getOperand(Op).getImm();
-  bool Flavor = MI->getOpcode() == X86::CMPCCXADDmr32 ||
-                MI->getOpcode() == X86::CMPCCXADDmr64 ||
-                MI->getOpcode() == X86::CMPCCXADDmr32_EVEX ||
-                MI->getOpcode() == X86::CMPCCXADDmr64_EVEX;
+  bool IsCMPCCXADD = X86::isCMPCCXADD(MI->getOpcode());
+
+  // clang-format off
   switch (Imm) {
   default: llvm_unreachable("Invalid condcode argument!");
   case    0: O << "o";  break;
   case    1: O << "no"; break;
   case    2: O << "b";  break;
-  case    3: O << (Flavor ? "nb" : "ae"); break;
-  case    4: O << (Flavor ?  "z" :  "e"); break;
-  case    5: O << (Flavor ? "nz" : "ne"); break;
+  case    3: O << (IsCMPCCXADD ? "nb" : "ae"); break;
+  case    4: O << (IsCMPCCXADD ?  "z" :  "e"); break;
+  case    5: O << (IsCMPCCXADD ? "nz" : "ne"); break;
   case    6: O << "be"; break;
-  case    7: O << (Flavor ? "nbe" : "a"); break;
+  case    7: O << (IsCMPCCXADD ? "nbe" : "a"); break;
   case    8: O << "s";  break;
   case    9: O << "ns"; break;
   case  0xa: O << "p";  break;
   case  0xb: O << "np"; break;
   case  0xc: O << "l";  break;
-  case  0xd: O << (Flavor ? "nl" : "ge"); break;
+  case  0xd: O << (IsCMPCCXADD ? "nl" : "ge"); break;
   case  0xe: O << "le"; break;
-  case  0xf: O << (Flavor ? "nle" : "g"); break;
+  case  0xf: O << (IsCMPCCXADD ? "nle" : "g"); break;
   }
+  // clang-format on
 }
 
 void X86InstPrinterCommon::printSSEAVXCC(const MCInst *MI, unsigned Op,

diff  --git a/llvm/utils/TableGen/X86RecognizableInstr.cpp b/llvm/utils/TableGen/X86RecognizableInstr.cpp
index 873f3aea053c60..5aa2e51c78ba29 100644
--- a/llvm/utils/TableGen/X86RecognizableInstr.cpp
+++ b/llvm/utils/TableGen/X86RecognizableInstr.cpp
@@ -26,17 +26,18 @@ using namespace X86Disassembler;
 
 std::string X86Disassembler::getMnemonic(const CodeGenInstruction *I,
                                          unsigned Variant) {
-  std::string AsmString = I->FlattenAsmStringVariants(I->AsmString, Variant);
-  StringRef Mnemonic(AsmString);
   // Extract a mnemonic assuming it's separated by \t
-  Mnemonic = Mnemonic.take_until([](char C) { return C == '\t'; });
+  std::string Mnemonic =
+      StringRef(I->FlattenAsmStringVariants(I->AsmString, Variant))
+          .take_until([](char C) { return C == '\t'; })
+          .str();
 
-  // Special case: CMOVCC, JCC, SETCC have "${cond}" in mnemonic.
+  // Special case: CMOVCC, JCC, SETCC, CMPCCXADD have "${cond}" in mnemonic.
   // Replace it with "CC" in-place.
-  size_t CondPos = Mnemonic.find("${cond}");
-  if (CondPos != StringRef::npos)
-    Mnemonic = AsmString.replace(CondPos, StringRef::npos, "CC");
-  return Mnemonic.upper();
+  auto CondPos = Mnemonic.find("${cond}");
+  if (CondPos != std::string::npos)
+    Mnemonic = Mnemonic.replace(CondPos, 7, "CC");
+  return StringRef(Mnemonic).upper();
 }
 
 bool X86Disassembler::isRegisterOperand(const Record *Rec) {


        


More information about the llvm-commits mailing list