MC/X86: Push immediate operands as immediates not expressions when possible.
authorDaniel Dunbar <daniel@zuster.org>
Sat, 13 Feb 2010 00:17:21 +0000 (00:17 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sat, 13 Feb 2010 00:17:21 +0000 (00:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96055 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/AsmParser/X86AsmParser.cpp
test/MC/AsmParser/X86/x86_64-new-encoder.s
test/MC/AsmParser/X86/x86_instructions.s
test/MC/AsmParser/X86/x86_operands.s

index 2c79eeb962b34a3c71a24fc69932e7ce2c93c0aa..84d7bb7a6f3c3065c8cd6234663e470ee1628863 100644 (file)
@@ -184,6 +184,14 @@ struct X86Operand : public MCParsedAsmOperand {
 
   bool isReg() const { return Kind == Register; }
 
+  void addExpr(MCInst &Inst, const MCExpr *Expr) const {
+    // Add as immediates when possible.
+    if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
+      Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
+    else
+      Inst.addOperand(MCOperand::CreateExpr(Expr));
+  }
+
   void addRegOperands(MCInst &Inst, unsigned N) const {
     assert(N == 1 && "Invalid number of operands!");
     Inst.addOperand(MCOperand::CreateReg(getReg()));
@@ -191,13 +199,13 @@ struct X86Operand : public MCParsedAsmOperand {
 
   void addImmOperands(MCInst &Inst, unsigned N) const {
     assert(N == 1 && "Invalid number of operands!");
-    Inst.addOperand(MCOperand::CreateExpr(getImm()));
+    addExpr(Inst, getImm());
   }
 
   void addImmSExt8Operands(MCInst &Inst, unsigned N) const {
     // FIXME: Support user customization of the render method.
     assert(N == 1 && "Invalid number of operands!");
-    Inst.addOperand(MCOperand::CreateExpr(getImm()));
+    addExpr(Inst, getImm());
   }
 
   void addMemOperands(MCInst &Inst, unsigned N) const {
@@ -205,7 +213,7 @@ struct X86Operand : public MCParsedAsmOperand {
     Inst.addOperand(MCOperand::CreateReg(getMemBaseReg()));
     Inst.addOperand(MCOperand::CreateImm(getMemScale()));
     Inst.addOperand(MCOperand::CreateReg(getMemIndexReg()));
-    Inst.addOperand(MCOperand::CreateExpr(getMemDisp()));
+    addExpr(Inst, getMemDisp());
     Inst.addOperand(MCOperand::CreateReg(getMemSegReg()));
   }
 
@@ -219,7 +227,7 @@ struct X86Operand : public MCParsedAsmOperand {
     Inst.addOperand(MCOperand::CreateReg(getMemBaseReg()));
     Inst.addOperand(MCOperand::CreateImm(getMemScale()));
     Inst.addOperand(MCOperand::CreateReg(getMemIndexReg()));
-    Inst.addOperand(MCOperand::CreateExpr(getMemDisp()));
+    addExpr(Inst, getMemDisp());
   }
 
   static X86Operand *CreateToken(StringRef Str, SMLoc Loc) {
index cdbac1e53b5592d5a641427f43215b583c32f66e..f00731217793278071b8499541e1dfd110b6b610 100644 (file)
@@ -7,24 +7,20 @@ movl  foo(%rip), %eax
 
 movb   $12, foo(%rip)
 // CHECK: movb $12, foo(%rip)
-// CHECK: encoding: [0xc6,0x05,A,A,A,A,B]
+// CHECK: encoding: [0xc6,0x05,A,A,A,A,0x0c]
 // CHECK:    fixup A - offset: 2, value: foo-1, kind: reloc_riprel_4byte
-// CHECK:    fixup B - offset: 6, value: 12, kind: FK_Data_1
 
 movw   $12, foo(%rip)
 // CHECK: movw $12, foo(%rip)
-// CHECK: encoding: [0x66,0xc7,0x05,A,A,A,A,B,B]
+// CHECK: encoding: [0x66,0xc7,0x05,A,A,A,A,0x0c,0x00]
 // CHECK:    fixup A - offset: 3, value: foo-2, kind: reloc_riprel_4byte
-// CHECK:    fixup B - offset: 7, value: 12, kind: FK_Data_2
 
 movl   $12, foo(%rip)
 // CHECK: movl $12, foo(%rip)
-// CHECK: encoding: [0xc7,0x05,A,A,A,A,B,B,B,B]
+// CHECK: encoding: [0xc7,0x05,A,A,A,A,0x0c,0x00,0x00,0x00]
 // CHECK:    fixup A - offset: 2, value: foo-4, kind: reloc_riprel_4byte
-// CHECK:    fixup B - offset: 6, value: 12, kind: FK_Data_4
 
 movq   $12, foo(%rip)
 // CHECK:  movq        $12, foo(%rip)
-// CHECK: encoding: [0x48,0xc7,0x05,A,A,A,A,B,B,B,B]
+// CHECK: encoding: [0x48,0xc7,0x05,A,A,A,A,0x0c,0x00,0x00,0x00]
 // CHECK:    fixup A - offset: 3, value: foo-4, kind: reloc_riprel_4byte
-// CHECK:    fixup B - offset: 7, value: 12, kind: FK_Data_4
index a74dcd24ea30255e1fabebd00ffaba6cbf9197f9..b558c2eb5f45158b4e1cd69265bf21ee52c2be21 100644 (file)
         repne;scasb
 
 // CHECK: lock
-// CHECK: cmpxchgb %al, 0(%ebx)
+// CHECK: cmpxchgb %al, (%ebx)
         lock;cmpxchgb %al, 0(%ebx)
 
 // CHECK: cs
-// CHECK: movb 0(%eax), %al
+// CHECK: movb (%eax), %al
         cs;movb 0(%eax), %al
 
 // CHECK: ss
-// CHECK: movb 0(%eax), %al
+// CHECK: movb (%eax), %al
         ss;movb 0(%eax), %al
 
 // CHECK: ds
-// CHECK: movb 0(%eax), %al
+// CHECK: movb (%eax), %al
         ds;movb 0(%eax), %al
 
 // CHECK: es
-// CHECK: movb 0(%eax), %al
+// CHECK: movb (%eax), %al
         es;movb 0(%eax), %al
 
 // CHECK: fs
-// CHECK: movb 0(%eax), %al
+// CHECK: movb (%eax), %al
         fs;movb 0(%eax), %al
 
 // CHECK: gs
-// CHECK: movb 0(%eax), %al
+// CHECK: movb (%eax), %al
         gs;movb 0(%eax), %al
 
 // CHECK: fadd %st(0)
index 433c9bf7729e1425a270567835d2dcadc848b91c..8e6543e7bd68bce6388c6f35288711c523038bb3 100644 (file)
@@ -24,7 +24,7 @@
         addl $1, (4+4)(%eax)
 # CHECK: addl $1, 8(%eax)
         addl $1, 8(%eax)
-# CHECK: addl $1, 0(%eax)
+# CHECK: addl $1, (%eax)
         addl $1, (%eax)
 # CHECK: addl $1, 4+4(,%eax)
         addl $1, (4+4)(,%eax)