[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 03:59:44 PST 2023
skan updated this revision to Diff 500411.
skan added a comment.
Combine duplicated code
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,19 @@
}
}
}
+ if (!HasRegOp) {
+ PrefixKind Kind = Prefix.determineOptimalKind();
+ 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144776.500411.patch
Type: text/x-patch
Size: 1631 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230225/af2fcb0f/attachment.bin>
More information about the llvm-commits
mailing list