This is an archive of the discontinued LLVM Phabricator instance.

[X86][MC] Assert unexpected form in emitREXPrefix, NFCI
ClosedPublic

Authored by skan on Feb 24 2023, 10:05 PM.

Details

Summary
  1. Add a variable HasRegOp to record if the instruction has a register operand
  2. Enumerate all the formats with a register operand in the switch
  3. Add a default (unreachable) label in the switch (suggested by @reames)

Diff Detail

Event Timeline

skan created this revision.Feb 24 2023, 10:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 24 2023, 10:05 PM
skan requested review of this revision.Feb 24 2023, 10:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 24 2023, 10:05 PM
skan edited the summary of this revision. (Show Details)Feb 24 2023, 10:06 PM
skan added reviewers: pengfei, craig.topper, RKSimon.
skan added a subscriber: reames.
pengfei added inline comments.Feb 25 2023, 3:16 AM
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
1196

Not sure others, but should this be unreachable too?

1255

Move this ahead?

skan updated this revision to Diff 500411.Feb 25 2023, 3:59 AM

Combine duplicated code

skan marked an inline comment as done.Feb 25 2023, 4:01 AM
skan added inline comments.
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
1196

It is reachable b/c the format can have an implicit register operand. If we removed this, the following command would crash

echo "movabsq 0x123456789abcdef, %rax" | llvm-mc --show-encoding

where movabsq is MOV64ao64 in TD

pengfei added inline comments.Feb 25 2023, 4:02 AM
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
1193

You intend to !NumOps || !HasRegOp?

skan updated this revision to Diff 500414.Feb 25 2023, 4:24 AM
skan marked 2 inline comments as done.

Address review comments

skan added inline comments.Feb 25 2023, 4:26 AM
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
1193

!NumOps || !HasRegOp is same as !HasRegOp b/c !NumOps implies !HasRegOp

pengfei added inline comments.Feb 25 2023, 4:30 AM
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
1195

How about move the check here:

if (HasRegOp)
  llvm_unreachable("Unexpected form in emitREXPrefix!");

Then you don't need the lambda expression.

skan updated this revision to Diff 500415.Feb 25 2023, 4:34 AM

simplify code

skan added inline comments.Feb 25 2023, 4:39 AM
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
1195

I haven't got your idea. Lambda is used to check HighByteReg. How can we achieve the same effect with your code?

pengfei added inline comments.Feb 25 2023, 4:46 AM
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
1195

Because you don't need to do the check and return twice with the change. Just do it in the end of the function.

skan marked 2 inline comments as done.Feb 25 2023, 5:42 AM
skan added inline comments.
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
1195

Got it, will do

skan updated this revision to Diff 500424.Feb 25 2023, 5:51 AM
skan marked an inline comment as done.

Address review comments: avoid lambda

pengfei accepted this revision.Feb 25 2023, 6:17 AM

LGTM.

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

We don't need the else here.

1198

This can also be [[fallthrough]];

This revision is now accepted and ready to land.Feb 25 2023, 6:17 AM
skan updated this revision to Diff 500426.Feb 25 2023, 6:31 AM

Address review comments: use fallthrough

skan retitled this revision from [X86][MC] Early bail out in emitREXPrefix, NFCI to [X86][MC] Assert unexpected form in emitREXPrefix, NFCI.Feb 25 2023, 6:36 AM
skan edited the summary of this revision. (Show Details)
skan updated this revision to Diff 500488.Feb 25 2023, 7:26 PM

Fix the compiler-rt test fail by adding format RawFrm

craig.topper added inline comments.Feb 25 2023, 7:42 PM
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
1196

assert(!HasRegOp && "Unexpected form in emitREXPrefix!")

skan updated this revision to Diff 500516.Feb 25 2023, 11:22 PM
skan marked an inline comment as done.

Address review comments: simplify code by using assert

skan updated this revision to Diff 500518.Feb 26 2023, 12:08 AM

Add macro NDEBUG b/c the variable HasRegOp is only used in assert

This revision was automatically updated to reflect the committed changes.