Skip to content

Commit 9c3b68d

Browse files
committed
[llvm-mca] Fix processing thumb instruction set
Differential revision: https://reviews.llvm.org/D91704
1 parent c80fbdf commit 9c3b68d

File tree

2 files changed

+2740
-3
lines changed

2 files changed

+2740
-3
lines changed

llvm/lib/MCA/InstrBuilder.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,9 @@ void InstrBuilder::populateWrites(InstrDesc &ID, const MCInst &MCI,
259259
// the opcode descriptor (MCInstrDesc).
260260
// 2. Uses start at index #(MCDesc.getNumDefs()).
261261
// 3. There can only be a single optional register definition, an it is
262-
// always the last operand of the sequence (excluding extra operands
263-
// contributed by variadic opcodes).
262+
// either the last operand of the sequence (excluding extra operands
263+
// contributed by variadic opcodes) or one of the explicit register
264+
// definitions. The latter occurs for some Thumb1 instructions.
264265
//
265266
// These assumptions work quite well for most out-of-order in-tree targets
266267
// like x86. This is mainly because the vast majority of instructions is
@@ -308,12 +309,18 @@ void InstrBuilder::populateWrites(InstrDesc &ID, const MCInst &MCI,
308309
// The first NumExplicitDefs register operands are expected to be register
309310
// definitions.
310311
unsigned CurrentDef = 0;
312+
unsigned OptionalDefIdx = MCDesc.getNumOperands() - 1;
311313
unsigned i = 0;
312314
for (; i < MCI.getNumOperands() && CurrentDef < NumExplicitDefs; ++i) {
313315
const MCOperand &Op = MCI.getOperand(i);
314316
if (!Op.isReg())
315317
continue;
316318

319+
if (MCDesc.OpInfo[CurrentDef].isOptionalDef()) {
320+
OptionalDefIdx = CurrentDef++;
321+
continue;
322+
}
323+
317324
WriteDescriptor &Write = ID.Writes[CurrentDef];
318325
Write.OpIndex = i;
319326
if (CurrentDef < NumWriteLatencyEntries) {
@@ -369,7 +376,7 @@ void InstrBuilder::populateWrites(InstrDesc &ID, const MCInst &MCI,
369376

370377
if (MCDesc.hasOptionalDef()) {
371378
WriteDescriptor &Write = ID.Writes[NumExplicitDefs + NumImplicitDefs];
372-
Write.OpIndex = MCDesc.getNumOperands() - 1;
379+
Write.OpIndex = OptionalDefIdx;
373380
// Assign a default latency for this write.
374381
Write.Latency = ID.MaxLatency;
375382
Write.SClassOrWriteResourceID = 0;

0 commit comments

Comments
 (0)