From 9607c40601b345c21af9de97ec03e124179efd24 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 8 Sep 2010 04:53:27 +0000 Subject: [PATCH] gas accepts xchg , as a synonym for xchg , . Add this to the mc assembler, fixing PR8061 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113346 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/AsmParser/X86AsmParser.cpp | 11 +++++++++++ test/MC/AsmParser/X86/x86_64-new-encoder.s | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/lib/Target/X86/AsmParser/X86AsmParser.cpp b/lib/Target/X86/AsmParser/X86AsmParser.cpp index cddf8ebfc07..58e4554ab03 100644 --- a/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -753,6 +753,7 @@ ParseInstruction(StringRef Name, SMLoc NameLoc, PatchedName = "vpclmulqdq"; } } + Operands.push_back(X86Operand::CreateToken(PatchedName, NameLoc)); if (ExtraImmOp) @@ -827,6 +828,16 @@ ParseInstruction(StringRef Name, SMLoc NameLoc, delete Operands[0]; Operands[0] = X86Operand::CreateToken("sldtw", NameLoc); } + + // The assembler accepts "xchgX , " and "xchgX , " as + // synonyms. Our tables only have the ", " form, so if we see the + // other operand order, swap them. + if (Name == "xchgb" || Name == "xchgw" || Name == "xchgl" || Name == "xchgq") + if (Operands.size() == 3 && + static_cast(Operands[1])->isMem() && + static_cast(Operands[2])->isReg()) { + std::swap(Operands[1], Operands[2]); + } return false; } diff --git a/test/MC/AsmParser/X86/x86_64-new-encoder.s b/test/MC/AsmParser/X86/x86_64-new-encoder.s index 3644147b167..7992972c988 100644 --- a/test/MC/AsmParser/X86/x86_64-new-encoder.s +++ b/test/MC/AsmParser/X86/x86_64-new-encoder.s @@ -168,3 +168,8 @@ L1: // CHECK: jrcxz L1 // CHECK: encoding: [0xe3,A] +// PR8061 +xchgl 368(%rax),%ecx +// CHECK: xchgl %ecx, 368(%rax) +xchgl %ecx, 368(%rax) +// CHECK: xchgl %ecx, 368(%rax)