Improve the heuristic to emit the alias if the number of hard-coded registers
authorBill Wendling <isanbard@gmail.com>
Wed, 15 Jun 2011 04:31:19 +0000 (04:31 +0000)
committerBill Wendling <isanbard@gmail.com>
Wed, 15 Jun 2011 04:31:19 +0000 (04:31 +0000)
are also greater than the alias.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133038 91177308-0d34-0410-b5e6-96231b3b80d8

test/MC/X86/x86-64.s
utils/TableGen/AsmWriterEmitter.cpp

index ca206da2ae36b7f8997e1ff004126e438c7460e4..a36ba25a6e7a21f5675c84f83a52f8caf2685c52 100644 (file)
@@ -232,10 +232,10 @@ cmovnzq %rbx, %rax
 
 // rdar://8407928
 // CHECK: inb  $127, %al
-// CHECK: inw  %dx, %ax
+// CHECK: inw  %dx
 // CHECK: outb %al, $127
-// CHECK: outw %ax, %dx
-// CHECK: inl  %dx, %eax
+// CHECK: outw %dx
+// CHECK: inl  %dx
 inb    $0x7f
 inw    %dx
 outb   $0x7f
@@ -244,12 +244,12 @@ inl       %dx
 
 
 // PR8114
-// CHECK: outb %al, %dx
-// CHECK: outb %al, %dx
-// CHECK: outw %ax, %dx
-// CHECK: outw %ax, %dx
-// CHECK: outl %eax, %dx
-// CHECK: outl %eax, %dx
+// CHECK: outb %dx
+// CHECK: outb %dx
+// CHECK: outw %dx
+// CHECK: outw %dx
+// CHECK: outl %dx
+// CHECK: outl %dx
 
 out    %al, (%dx)
 outb   %al, (%dx)
@@ -258,12 +258,12 @@ outw      %ax, (%dx)
 out    %eax, (%dx)
 outl   %eax, (%dx)
 
-// CHECK: inb  %dx, %al
-// CHECK: inb  %dx, %al
-// CHECK: inw  %dx, %ax
-// CHECK: inw  %dx, %ax
-// CHECK: inl  %dx, %eax
-// CHECK: inl  %dx, %eax
+// CHECK: inb  %dx
+// CHECK: inb  %dx
+// CHECK: inw  %dx
+// CHECK: inw  %dx
+// CHECK: inl  %dx
+// CHECK: inl  %dx
 
 in     (%dx), %al
 inb    (%dx), %al
index 3eedf10f7cb3e9b213a24f44b4e5238dff48db2e..bfc63c0cf85779977fa58242d8bc7d35d2a203f2 100644 (file)
@@ -842,6 +842,26 @@ static unsigned CountNumOperands(StringRef AsmString) {
   return NumOps;
 }
 
+static unsigned CountResultNumOperands(StringRef AsmString) {
+  unsigned NumOps = 0;
+  std::pair<StringRef, StringRef> ASM = AsmString.split('\t');
+
+  if (!ASM.second.empty()) {
+    size_t I = ASM.second.find('{');
+    StringRef Str = ASM.second;
+    if (I != StringRef::npos)
+      Str = ASM.second.substr(I, ASM.second.find('|', I));
+
+    ASM = Str.split(' ');
+
+    do {
+      ++NumOps;
+      ASM = ASM.second.split(' ');
+    } while (!ASM.second.empty());
+  }
+
+  return NumOps;
+}
 
 void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
   CodeGenTarget Target(Records);
@@ -887,9 +907,11 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
            II = Aliases.begin(), IE = Aliases.end(); II != IE; ++II) {
       const CodeGenInstAlias *CGA = *II;
       unsigned LastOpNo = CGA->ResultInstOperandIndex.size();
+      unsigned NumResultOps =
+        CountResultNumOperands(CGA->ResultInst->AsmString);
 
       // Don't emit the alias if it has more operands than what it's aliasing.
-      if (LastOpNo < CountNumOperands(CGA->AsmString))
+      if (NumResultOps < CountNumOperands(CGA->AsmString))
         continue;
 
       IAPrinter *IAP = new IAPrinter(AWI, CGA->Result->getAsString(),