Skip to content

Commit 37edc52

Browse files
author
kbelochapka
committed
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314044 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent cffa4f4 commit 37edc52

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/Target/X86/AsmParser/X86AsmParser.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,9 +1985,12 @@ std::unique_ptr<X86Operand> X86AsmParser::ParseMemOperand(unsigned SegReg,
19851985
// memory operand consumed.
19861986
} else {
19871987
SMLoc ExprEnd;
1988+
getLexer().UnLex(AsmToken(AsmToken::LParen, "("));
19881989

1989-
// It must be an parenthesized expression, parse it now.
1990-
if (getParser().parseParenExpression(Disp, ExprEnd))
1990+
// It must be either an parenthesized expression, or an expression that
1991+
// begins from a parenthesized expression, parse it now. Example: (1+2) or
1992+
// (1+2)+3
1993+
if (getParser().parseExpression(Disp, ExprEnd))
19911994
return nullptr;
19921995

19931996
// After parsing the base expression we could either have a parenthesized

test/MC/X86/x86_64-encoding.s

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,15 @@ sha256msg2 (%rax), %xmm2
251251
// CHECK: pinsrw $3, %ecx, %xmm5
252252
// CHECK: encoding: [0x66,0x0f,0xc4,0xe9,0x03]
253253
pinsrw $3, %rcx, %xmm5
254+
255+
//CHECK movq 12(%rdi), %rsi
256+
//CHECK encoding: [0x48,0x8b,0x77,0x0c]
257+
movq 16+0-4(%rdi),%rsi
258+
259+
//CHECK movq 12(%rdi), %rsi
260+
//CHECK encoding: [0x48,0x8b,0x77,0x0c]
261+
movq (16+(0-4))(%rdi),%rsi
262+
263+
//CHECK movq 12(%rdi), %rsi
264+
//CHECK encoding: [0x48,0x8b,0x77,0x0c]
265+
movq (16+0)-1+1-2+2-3+3-4+4-5+5-6+6-(4)(%rdi),%rsi

0 commit comments

Comments
 (0)