[PATCH] D144776: [X86][MC] Early bail out in emitREXPrefix, NFCI
Kan Shengchen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 25 04:24:06 PST 2023
skan updated this revision to Diff 500414.
skan marked 2 inline comments as done.
skan added a comment.
Address review comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D144776/new/
https://reviews.llvm.org/D144776
Files:
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
Index: llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
===================================================================
--- llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
+++ llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
@@ -1160,20 +1160,17 @@
if (!STI.hasFeature(X86::Is64Bit))
return None;
X86OpcodePrefixHelper Prefix(*Ctx.getRegisterInfo());
- bool UsesHighByteReg = false;
const MCInstrDesc &Desc = MCII.get(MI.getOpcode());
uint64_t TSFlags = Desc.TSFlags;
Prefix.setW(TSFlags & X86II::REX_W);
unsigned NumOps = MI.getNumOperands();
- if (!NumOps) {
- PrefixKind Kind = Prefix.determineOptimalKind();
- Prefix.emit(OS);
- return Kind;
- }
- unsigned CurOp = X86II::getOperandBias(Desc);
+ bool UsesHighByteReg = false;
+ bool HasRegOp = false;
+ unsigned CurOp = NumOps ? X86II::getOperandBias(Desc) : 0;
for (unsigned i = CurOp; i != NumOps; ++i) {
const MCOperand &MO = MI.getOperand(i);
if (MO.isReg()) {
+ HasRegOp = true;
unsigned Reg = MO.getReg();
if (Reg == X86::AH || Reg == X86::BH || Reg == X86::CH || Reg == X86::DH)
UsesHighByteReg = true;
@@ -1193,7 +1190,26 @@
}
}
}
+ PrefixKind Kind;
+ auto determineKindAndCheck = [&]() {
+ Kind = Prefix.determineOptimalKind();
+ if (Kind && UsesHighByteReg)
+ report_fatal_error(
+ "Cannot encode high byte register in REX-prefixed instruction");
+ };
+ if (!HasRegOp) {
+ determineKindAndCheck();
+ Prefix.emit(OS);
+ return Kind;
+ }
switch (TSFlags & X86II::FormMask) {
+ default:
+ llvm_unreachable("Unexpected form in emitREXPrefix!");
+ case X86II::RawFrmMemOffs:
+ case X86II::RawFrmSrc:
+ case X86II::RawFrmDst:
+ case X86II::RawFrmDstSrc:
+ break;
case X86II::AddRegFrm:
Prefix.setB(MI, CurOp++);
break;
@@ -1245,10 +1261,7 @@
Prefix.setB(MI, CurOp++);
break;
}
- PrefixKind Kind = Prefix.determineOptimalKind();
- if (Kind && UsesHighByteReg)
- report_fatal_error(
- "Cannot encode high byte register in REX-prefixed instruction");
+ determineKindAndCheck();
Prefix.emit(OS);
return Kind;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144776.500414.patch
Type: text/x-patch
Size: 2174 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230225/99912d18/attachment-0001.bin>
More information about the llvm-commits
mailing list