diff --git a/lib/Target/X86/AsmParser/X86AsmParser.cpp b/lib/Target/X86/AsmParser/X86AsmParser.cpp index bb6e05c2864..01ccc50adf9 100644 --- a/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -911,6 +911,16 @@ ParseInstruction(StringRef Name, SMLoc NameLoc, Operands.erase(Operands.begin() + 2); } + // FIXME: Hack to handle "f{mul*,add*} st(0), $op" the same as + // "f{mul*,add*} $op", since they commute. + if ((Name.startswith("fmul") || Name.startswith("fadd")) && + Operands.size() == 3 && + static_cast(Operands[1])->isReg() && + static_cast(Operands[1])->getReg() == X86::ST0) { + delete Operands[1]; + Operands.erase(Operands.begin() + 1); + } + // FIXME: Hack to handle "imul , B" which is an alias for "imul , B, // B". if (Name.startswith("imul") && Operands.size() == 3 && diff --git a/test/MC/AsmParser/X86/x86_instructions.s b/test/MC/AsmParser/X86/x86_instructions.s index aea617dff00..b72374db46f 100644 --- a/test/MC/AsmParser/X86/x86_instructions.s +++ b/test/MC/AsmParser/X86/x86_instructions.s @@ -353,3 +353,11 @@ mov %rdx, %cr8 mov %rdx, %cr15 // CHECK: movq %rdx, %cr15 // CHECK: encoding: [0x44,0x0f,0x22,0xfa] + +// rdar://8456371 - Handle commutable instructions written backward. +// CHECK: faddp %st(1) +// CHECK: fmulp %st(2) +faddp %st, %st(1) +fmulp %st, %st(2) + +