]> granicus.if.org Git - llvm/commitdiff
[X86] [MC] fixed non optimal encoding of instruction memory operand (PR24038).
authorKonstantin Belochapka <Konstantin.belochapka@sony.com>
Fri, 22 Sep 2017 23:37:48 +0000 (23:37 +0000)
committerKonstantin Belochapka <Konstantin.belochapka@sony.com>
Fri, 22 Sep 2017 23:37:48 +0000 (23:37 +0000)
Fixed suboptimal encoding of instruction memory operand when assembler is used to select 32 bit fixup rather than 8 bit immediate for encoding memory offset value.
Differential Revision: https://reviews.llvm.org/D38117

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

lib/Target/X86/AsmParser/X86AsmParser.cpp
test/MC/X86/x86_64-encoding.s

index 3e1438739dbda8e1f81ac539d9aa8a9f586d2b69..d9053113c4ce9865ab9f01f4d0b6999ab40d3dc7 100644 (file)
@@ -1985,9 +1985,12 @@ std::unique_ptr<X86Operand> X86AsmParser::ParseMemOperand(unsigned SegReg,
       // memory operand consumed.
     } else {
       SMLoc ExprEnd;
+      getLexer().UnLex(AsmToken(AsmToken::LParen, "("));
 
-      // It must be an parenthesized expression, parse it now.
-      if (getParser().parseParenExpression(Disp, ExprEnd))
+      // It must be either an parenthesized expression, or an expression that
+      // begins from a parenthesized expression, parse it now. Example: (1+2) or
+      // (1+2)+3
+      if (getParser().parseExpression(Disp, ExprEnd))
         return nullptr;
 
       // After parsing the base expression we could either have a parenthesized
index c502ed4664338b5796f88454c99713e76265cbf3..f0fdb72aaf23ad08337d8590d9796db4e07a0d3d 100644 (file)
@@ -251,3 +251,15 @@ sha256msg2 (%rax), %xmm2
 // CHECK: pinsrw $3, %ecx, %xmm5
 // CHECK: encoding: [0x66,0x0f,0xc4,0xe9,0x03]
           pinsrw $3, %rcx, %xmm5
+
+//CHECK   movq 12(%rdi), %rsi
+//CHECK   encoding: [0x48,0x8b,0x77,0x0c]
+    movq       16+0-4(%rdi),%rsi
+
+//CHECK   movq 12(%rdi), %rsi
+//CHECK   encoding: [0x48,0x8b,0x77,0x0c]
+    movq       (16+(0-4))(%rdi),%rsi
+
+//CHECK   movq 12(%rdi), %rsi
+//CHECK   encoding: [0x48,0x8b,0x77,0x0c]
+    movq       (16+0)-1+1-2+2-3+3-4+4-5+5-6+6-(4)(%rdi),%rsi