diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp index 90bd4e3d1b5a..7d62c466b275 100644 --- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -856,6 +856,16 @@ ParseInstruction(StringRef Name, SMLoc NameLoc, std::swap(Operands[1], Operands[2]); } + // The assembler accepts "testX , " and "testX , " as + // synonyms. Our tables only have the ", " form, so if we see the + // other operand order, swap them. + if (Name == "testb" || Name == "testw" || Name == "testl" || Name == "testq") + if (Operands.size() == 3 && + static_cast(Operands[1])->isReg() && + static_cast(Operands[2])->isMem()) { + std::swap(Operands[1], Operands[2]); + } + return false; } diff --git a/llvm/test/MC/AsmParser/X86/x86_32-new-encoder.s b/llvm/test/MC/AsmParser/X86/x86_32-new-encoder.s index ed8ee868196d..6d9d7ed40749 100644 --- a/llvm/test/MC/AsmParser/X86/x86_32-new-encoder.s +++ b/llvm/test/MC/AsmParser/X86/x86_32-new-encoder.s @@ -452,3 +452,10 @@ sysret sysretl // CHECK: sysretl // CHECK: encoding: [0x0f,0x07] + +// rdar://8018260 +testl %ecx, -24(%ebp) +// CHECK: testl -24(%ebp), %ecx +testl -24(%ebp), %ecx +// CHECK: testl -24(%ebp), %ecx +