This is an archive of the discontinued LLVM Phabricator instance.

[X86][MC]Fix wrong action for encode movdir64b
ClosedPublic

Authored by XinWang10 on Mar 12 2023, 8:50 PM.

Details

Summary

Movdir64b is special for its mem operand, 67 prefex can not only modify its add size,
so it's mem base and index reg should be the same type as source reg, such as
movdir64b (%rdx), rcx, and could not be movdir64b (%edx), rcx.
Now llvm-mc can encode the asm 'movdir64b (%edx), rcx' but the result is the same as
'movdir64b (%edx), ecx', which offend users' intention, while gcc will object this
action and give a warning.
I add 3 new mem descriptions to let llvm-mc to report the same error.

Diff Detail

Event Timeline

XinWang10 created this revision.Mar 12 2023, 8:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2023, 8:50 PM
XinWang10 requested review of this revision.Mar 12 2023, 8:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2023, 8:50 PM
XinWang10 retitled this revision from Fix wrong action for encode movdir64b to [X86][MC]Fix wrong action for encode movdir64b.Mar 12 2023, 9:23 PM
skan added a comment.Mar 12 2023, 10:56 PM

typo discriptions?

skan added a comment.Mar 12 2023, 11:10 PM

Now llvm-mc can encode the asm 'movdir64b (%edx), rcx' but the result is the same as
'movdir64b (%edx), ecx', which offend users' intention, while gcc will object this
action and give a warning.

I am confused about this statement.

  1. What does the "Now" mean here? Before this patch or after this patch?
  2. I can only see memory operand change in this patch, why it affects the register operand?
XinWang10 edited the summary of this revision. (Show Details)Mar 12 2023, 11:36 PM

Now llvm-mc can encode the asm 'movdir64b (%edx), rcx' but the result is the same as
'movdir64b (%edx), ecx', which offend users' intention, while gcc will object this
action and give a warning.

I am confused about this statement.

  1. What does the "Now" mean here? Before this patch or after this patch?
  2. I can only see memory operand change in this patch, why it affects the register operand?

For 1, Now means before, after this patch, we will report errors like gcc.
For 2, this instruction require the source reg operand consistent with mem base reg and index reg,
I change the mem operand to match their source register operand.

typo discriptions?

updated.

craig.topper added inline comments.Mar 13 2023, 4:47 PM
llvm/lib/Target/X86/AsmParser/X86Operand.h
395

Do you need to include X86::EIP?

398

Do you need to include X86::EIZ?

406

Do you need to include X86::RIP?

409

Do you need to include X86::RIZ?

XinWang10 updated this revision to Diff 504925.Mar 13 2023, 8:52 PM
  • add missing EIP/RIP for base reg
craig.topper added a comment.EditedMar 13 2023, 8:56 PM

Test for rip/eip?

XinWang10 marked 2 inline comments as done.Mar 13 2023, 8:57 PM
XinWang10 added inline comments.
llvm/lib/Target/X86/AsmParser/X86Operand.h
395

Thanks for point it, updated.

398

I search it and it is used in decoding? seems EIZ can not be used in encode, I try it with gas 'movdir64b 291(%esi, %eiz, 4), %ebx', and report 'Error: bad register name `%eiz''

409

ditto

craig.topper added inline comments.Mar 13 2023, 9:24 PM
llvm/lib/Target/X86/AsmParser/X86Operand.h
398

gas requires .allow_index_reg directive to enable riz/eiz parsing.

XinWang10 marked an inline comment as done.
  • consider eiz as index reg and add tests
XinWang10 marked 3 inline comments as done.Mar 13 2023, 10:42 PM
XinWang10 added inline comments.
llvm/lib/Target/X86/AsmParser/X86Operand.h
398

gas requires .allow_index_reg directive to enable riz/eiz parsing.

It worked. Will do.

craig.topper added inline comments.Mar 14 2023, 8:45 AM
llvm/lib/Target/X86/AsmParser/X86Operand.h
395

Why do you need parentheses around !X86MCRegisterClasses[X86::GR32RegClassID].contains(getMemBaseReg()?

396

Why not !=

XinWang10 updated this revision to Diff 505350.Mar 14 2023, 7:11 PM
XinWang10 marked an inline comment as done.
  • simplify the condition expr
  • remove redundant parentheses
  • remove redundant parentheses
XinWang10 marked 2 inline comments as done.Mar 14 2023, 10:46 PM
This revision is now accepted and ready to land.Mar 14 2023, 10:54 PM
skan accepted this revision.Mar 14 2023, 11:16 PM

LGTM

This revision was landed with ongoing or failed builds.Mar 17 2023, 12:30 AM
This revision was automatically updated to reflect the committed changes.

Thanks for review~