add support for the commuted form of the test instruction, rdar://8018260.
[oota-llvm.git] / lib / Target / X86 / AsmParser / X86AsmParser.cpp
index 90bd4e3d1b5afc44939aff9a01a60554a0eb70c2..7d62c466b275a0cecb334d07d72870f4ee32f0ee 100644 (file)
@@ -856,6 +856,16 @@ ParseInstruction(StringRef Name, SMLoc NameLoc,
       std::swap(Operands[1], Operands[2]);
     }
 
+  // The assembler accepts "testX <reg>, <mem>" and "testX <mem>, <reg>" as
+  // synonyms.  Our tables only have the "<mem>, <reg>" 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<X86Operand*>(Operands[1])->isReg() &&
+        static_cast<X86Operand*>(Operands[2])->isMem()) {
+      std::swap(Operands[1], Operands[2]);
+    }
+  
   return false;
 }