Skip to content

Commit e616f68

Browse files
phoebewangyuxuanchen1997
authored andcommitted
[X86][MC] Check AdSize16 for 16-bit addressing (#99761)
Summary: Fixes: #99735 Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251195
1 parent 7466d62 commit e616f68

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,9 +691,12 @@ void X86MCCodeEmitter::emitMemModRMByte(
691691

692692
unsigned BaseRegNo = BaseReg ? getX86RegNum(Base) : -1U;
693693

694+
bool IsAdSize16 = STI.hasFeature(X86::Is32Bit) &&
695+
(TSFlags & X86II::AdSizeMask) == X86II::AdSize16;
696+
694697
// 16-bit addressing forms of the ModR/M byte have a different encoding for
695698
// the R/M field and are far more limited in which registers can be used.
696-
if (X86_MC::is16BitMemOperand(MI, Op, STI)) {
699+
if (IsAdSize16 || X86_MC::is16BitMemOperand(MI, Op, STI)) {
697700
if (BaseReg) {
698701
// For 32-bit addressing, the row and column values in Table 2-2 are
699702
// basically the same. It's AX/CX/DX/BX/SP/BP/SI/DI in that order, with

llvm/test/MC/X86/x86-32-coverage.s

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10790,7 +10790,7 @@ btcl $4, (%eax)
1079010790
movdir64b 485498096, %ecx
1079110791

1079210792
// CHECK: movdir64b 485498096, %cx
10793-
// CHECK: # encoding: [0x67,0x66,0x0f,0x38,0xf8,0x0d,0xf0,0x1c,0xf0,0x1c]
10793+
// CHECK: # encoding: [0x67,0x66,0x0f,0x38,0xf8,0x0e,0xf0,0x1c]
1079410794
movdir64b 485498096, %cx
1079510795

1079610796
// CHECK: movdir64b (%edx), %eax
@@ -10877,6 +10877,10 @@ enqcmd (%bx,%di), %di
1087710877
// CHECK: encoding: [0x67,0xf2,0x0f,0x38,0xf8,0x81,0xc0,0x1f]
1087810878
enqcmd 8128(%bx,%di), %ax
1087910879

10880+
// CHECK: enqcmd 485498096, %cx
10881+
// CHECK: encoding: [0x67,0xf2,0x0f,0x38,0xf8,0x0e,0xf0,0x1c]
10882+
enqcmd 485498096, %cx
10883+
1088010884
// CHECK: enqcmds (%bx,%di), %di
1088110885
// CHECK: encoding: [0x67,0xf3,0x0f,0x38,0xf8,0x39]
1088210886
enqcmds (%bx,%di), %di
@@ -10885,6 +10889,10 @@ enqcmds (%bx,%di), %di
1088510889
// CHECK: encoding: [0x67,0xf3,0x0f,0x38,0xf8,0x81,0xc0,0x1f]
1088610890
enqcmds 8128(%bx,%di), %ax
1088710891

10892+
// CHECK: enqcmds 485498096, %cx
10893+
// CHECK: encoding: [0x67,0xf3,0x0f,0x38,0xf8,0x0e,0xf0,0x1c]
10894+
enqcmds 485498096, %cx
10895+
1088810896
// CHECK: serialize
1088910897
// CHECK: encoding: [0x0f,0x01,0xe8]
1089010898
serialize

0 commit comments

Comments
 (0)