From 3477711ec7f72ee79a7709f6cbeb4907df334430 Mon Sep 17 00:00:00 2001 From: Konstantin Belochapka Date: Fri, 22 Sep 2017 23:37:48 +0000 Subject: [PATCH] [X86] [MC] fixed non optimal encoding of instruction memory operand (PR24038). 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 llvm-svn: 314044 --- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp | 7 +++++-- llvm/test/MC/X86/x86_64-encoding.s | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp index 3e14387..d905311 100644 --- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -1985,9 +1985,12 @@ std::unique_ptr 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 diff --git a/llvm/test/MC/X86/x86_64-encoding.s b/llvm/test/MC/X86/x86_64-encoding.s index c502ed4..f0fdb72 100644 --- a/llvm/test/MC/X86/x86_64-encoding.s +++ b/llvm/test/MC/X86/x86_64-encoding.s @@ -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 -- 2.7.4