add support for the commuted form of the test instruction, rdar://8018260.
authorChris Lattner <sabre@nondot.org>
Wed, 8 Sep 2010 05:51:12 +0000 (05:51 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 8 Sep 2010 05:51:12 +0000 (05:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113352 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/AsmParser/X86AsmParser.cpp
test/MC/AsmParser/X86/x86_32-new-encoder.s

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;
 }
 
index ed8ee868196db08c23682caa048bc1f1001697cd..6d9d7ed40749045fade197747dea3fa8dc1772f2 100644 (file)
@@ -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
+