Skip to content

Commit 84cf12c

Browse files
XinWang10justinfargnoli
authored andcommitted
[X86][MC] Fix wrong action when encoding enqcmd/enqcmds (llvm#77571)
Mentioned in llvm#77293, enqcmd/enqcmds are special for its mem operand, like movdir64b(see llvm@4dd5e9c60efa9), 0x67 prefix can not only modify its address size, so it's mem base and index reg should be the same type as source reg.
1 parent 653da75 commit 84cf12c

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

llvm/lib/Target/X86/X86InstrMisc.td

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,28 +1523,28 @@ def MOVDIR64B64_EVEX : I<0xF8, MRMSrcMem, (outs), (ins GR64:$dst, i512mem_GR64:$
15231523
// ENQCMD/S - Enqueue 64-byte command as user with 64-byte write atomicity
15241524
//
15251525
let SchedRW = [WriteStore], Defs = [EFLAGS] in {
1526-
def ENQCMD16 : I<0xF8, MRMSrcMem, (outs), (ins GR16:$dst, i512mem:$src),
1526+
def ENQCMD16 : I<0xF8, MRMSrcMem, (outs), (ins GR16:$dst, i512mem_GR16:$src),
15271527
"enqcmd\t{$src, $dst|$dst, $src}",
15281528
[(set EFLAGS, (X86enqcmd GR16:$dst, addr:$src))]>,
15291529
T8, XD, AdSize16, Requires<[HasENQCMD, Not64BitMode]>;
1530-
def ENQCMD32 : I<0xF8, MRMSrcMem, (outs), (ins GR32:$dst, i512mem:$src),
1530+
def ENQCMD32 : I<0xF8, MRMSrcMem, (outs), (ins GR32:$dst, i512mem_GR32:$src),
15311531
"enqcmd\t{$src, $dst|$dst, $src}",
15321532
[(set EFLAGS, (X86enqcmd GR32:$dst, addr:$src))]>,
15331533
T8, XD, AdSize32, Requires<[HasENQCMD]>;
1534-
def ENQCMD64 : I<0xF8, MRMSrcMem, (outs), (ins GR64:$dst, i512mem:$src),
1534+
def ENQCMD64 : I<0xF8, MRMSrcMem, (outs), (ins GR64:$dst, i512mem_GR64:$src),
15351535
"enqcmd\t{$src, $dst|$dst, $src}",
15361536
[(set EFLAGS, (X86enqcmd GR64:$dst, addr:$src))]>,
15371537
T8, XD, AdSize64, Requires<[HasENQCMD, In64BitMode]>;
15381538

1539-
def ENQCMDS16 : I<0xF8, MRMSrcMem, (outs), (ins GR16:$dst, i512mem:$src),
1539+
def ENQCMDS16 : I<0xF8, MRMSrcMem, (outs), (ins GR16:$dst, i512mem_GR16:$src),
15401540
"enqcmds\t{$src, $dst|$dst, $src}",
15411541
[(set EFLAGS, (X86enqcmds GR16:$dst, addr:$src))]>,
15421542
T8, XS, AdSize16, Requires<[HasENQCMD, Not64BitMode]>;
1543-
def ENQCMDS32 : I<0xF8, MRMSrcMem, (outs), (ins GR32:$dst, i512mem:$src),
1543+
def ENQCMDS32 : I<0xF8, MRMSrcMem, (outs), (ins GR32:$dst, i512mem_GR32:$src),
15441544
"enqcmds\t{$src, $dst|$dst, $src}",
15451545
[(set EFLAGS, (X86enqcmds GR32:$dst, addr:$src))]>,
15461546
T8, XS, AdSize32, Requires<[HasENQCMD]>;
1547-
def ENQCMDS64 : I<0xF8, MRMSrcMem, (outs), (ins GR64:$dst, i512mem:$src),
1547+
def ENQCMDS64 : I<0xF8, MRMSrcMem, (outs), (ins GR64:$dst, i512mem_GR64:$src),
15481548
"enqcmds\t{$src, $dst|$dst, $src}",
15491549
[(set EFLAGS, (X86enqcmds GR64:$dst, addr:$src))]>,
15501550
T8, XS, AdSize64, Requires<[HasENQCMD, In64BitMode]>;

llvm/test/MC/X86/index-operations.s

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,61 @@ movdir64b 291(%esi, %eiz, 4), %ebx
188188

189189
movdir64b 291(%rsi, %riz, 4), %rbx
190190
// 64: movdir64b 291(%rsi,%riz,4), %rbx # encoding: [0x66,0x0f,0x38,0xf8,0x9c,0xa6,0x23,0x01,0x00,0x00]
191+
192+
enqcmd 291(%si), %ecx
193+
// ERR64: error: invalid 16-bit base register
194+
// ERR32: invalid operand
195+
// ERR16: invalid operand
196+
197+
enqcmd 291(%esi), %cx
198+
// ERR64: error: invalid operand for instruction
199+
// ERR32: invalid operand
200+
// ERR16: invalid operand
201+
202+
enqcmd (%rdx), %r15d
203+
// ERR64: [[#@LINE-1]]:[[#]]: error: invalid operand
204+
205+
enqcmd (%edx), %r15
206+
// ERR64: [[#@LINE-1]]:[[#]]: error: invalid operand
207+
208+
enqcmd (%eip), %ebx
209+
// 64: enqcmd (%eip), %ebx # encoding: [0x67,0xf2,0x0f,0x38,0xf8,0x1d,0x00,0x00,0x00,0x00]
210+
211+
enqcmd (%rip), %rbx
212+
// 64: enqcmd (%rip), %rbx # encoding: [0xf2,0x0f,0x38,0xf8,0x1d,0x00,0x00,0x00,0x00]
213+
214+
enqcmd 291(%esi, %eiz, 4), %ebx
215+
// 64: enqcmd 291(%esi,%eiz,4), %ebx # encoding: [0x67,0xf2,0x0f,0x38,0xf8,0x9c,0xa6,0x23,0x01,0x00,0x00]
216+
// 32: enqcmd 291(%esi,%eiz,4), %ebx # encoding: [0xf2,0x0f,0x38,0xf8,0x9c,0xa6,0x23,0x01,0x00,0x00]
217+
218+
enqcmd 291(%rsi, %riz, 4), %rbx
219+
// 64: enqcmd 291(%rsi,%riz,4), %rbx # encoding: [0xf2,0x0f,0x38,0xf8,0x9c,0xa6,0x23,0x01,0x00,0x00]
220+
221+
enqcmds 291(%si), %ecx
222+
// ERR64: error: invalid 16-bit base register
223+
// ERR32: invalid operand
224+
// ERR16: invalid operand
225+
226+
enqcmds 291(%esi), %cx
227+
// ERR64: error: invalid operand for instruction
228+
// ERR32: invalid operand
229+
// ERR16: invalid operand
230+
231+
enqcmds (%rdx), %r15d
232+
// ERR64: [[#@LINE-1]]:[[#]]: error: invalid operand
233+
234+
enqcmds (%edx), %r15
235+
// ERR64: [[#@LINE-1]]:[[#]]: error: invalid operand
236+
237+
enqcmds (%eip), %ebx
238+
// 64: enqcmds (%eip), %ebx # encoding: [0x67,0xf3,0x0f,0x38,0xf8,0x1d,0x00,0x00,0x00,0x00]
239+
240+
enqcmds (%rip), %rbx
241+
// 64: enqcmds (%rip), %rbx # encoding: [0xf3,0x0f,0x38,0xf8,0x1d,0x00,0x00,0x00,0x00]
242+
243+
enqcmds 291(%esi, %eiz, 4), %ebx
244+
// 64: enqcmds 291(%esi,%eiz,4), %ebx # encoding: [0x67,0xf3,0x0f,0x38,0xf8,0x9c,0xa6,0x23,0x01,0x00,0x00]
245+
// 32: enqcmds 291(%esi,%eiz,4), %ebx # encoding: [0xf3,0x0f,0x38,0xf8,0x9c,0xa6,0x23,0x01,0x00,0x00]
246+
247+
enqcmds 291(%rsi, %riz, 4), %rbx
248+
// 64: enqcmds 291(%rsi,%riz,4), %rbx # encoding: [0xf3,0x0f,0x38,0xf8,0x9c,0xa6,0x23,0x01,0x00,0x00]

0 commit comments

Comments
 (0)