Skip to content

Commit deb3464

Browse files
authored
[RISCV] Add Tied operands in Xqcicm instructions and changes to handle a single tied operand in source DAG and instruction (#145538)
Tied Operands change is required for adding codegen patterns for Qualcomm uC Xqcicm instructions which will be done in a follow-up PR. This change leads to one of instructions getting compressed even when it shouldn't be. This case was not covered in #143660. Added changes to correctly handle this case.
1 parent 901e139 commit deb3464

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -596,17 +596,20 @@ class QCILICC<bits<3> funct3, bits<2> funct2, DAGOperand InTyRs2, string opcodes
596596

597597
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
598598
class QCIMVCC<bits<3> funct3, string opcodestr>
599-
: RVInstR4<0b00, funct3, OPC_CUSTOM_2, (outs GPRNoX0:$rd),
600-
(ins GPRNoX0:$rs1, GPRNoX0:$rs2, GPRNoX0:$rs3),
601-
opcodestr, "$rd, $rs1, $rs2, $rs3">;
599+
: RVInstR4<0b00, funct3, OPC_CUSTOM_2, (outs GPRNoX0:$rd_wb),
600+
(ins GPRNoX0:$rd, GPRNoX0:$rs1, GPRNoX0:$rs2, GPRNoX0:$rs3),
601+
opcodestr, "$rd, $rs1, $rs2, $rs3"> {
602+
let Constraints = "$rd = $rd_wb";
603+
}
602604

603605
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
604606
class QCIMVCCI<bits<3> funct3, string opcodestr, DAGOperand immType>
605-
: RVInstR4<0b10, funct3, OPC_CUSTOM_2, (outs GPRNoX0:$rd),
606-
(ins GPRNoX0:$rs1, immType:$imm, GPRNoX0:$rs3),
607+
: RVInstR4<0b10, funct3, OPC_CUSTOM_2, (outs GPRNoX0:$rd_wb),
608+
(ins GPRNoX0:$rd, GPRNoX0:$rs1, immType:$imm, GPRNoX0:$rs3),
607609
opcodestr, "$rd, $rs1, $imm, $rs3"> {
608610
bits<5> imm;
609-
611+
612+
let Constraints = "$rd = $rd_wb";
610613
let rs2 = imm;
611614
}
612615

llvm/test/MC/RISCV/xqcicm-valid.s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,9 @@ qc.mveqi x9, x9, 0, x12
135135
# CHECK-ENC: encoding: [0x06,0xae]
136136
qc.mvltui x9, x9, 1, x12
137137

138+
# Following instruction should not be compressed
139+
140+
# CHECK-INST: qc.mveqi a0, s1, 0, a2
141+
# CHECK-ENC: encoding: [0x5b,0x85,0x04,0x64]
142+
qc.mveqi x10, x9, 0, x12
143+

llvm/utils/TableGen/CompressInstEmitter.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ class CompressInstEmitter {
137137
StringMap<unsigned> &SourceOperands,
138138
StringMap<unsigned> &DestOperands,
139139
const DagInit *SourceDag, const DagInit *DestDag,
140-
IndexedMap<OpData> &SourceOperandMap);
140+
IndexedMap<OpData> &SourceOperandMap,
141+
bool HasSourceTiedOp);
141142

142143
void createInstOperandMapping(const Record *Rec, const DagInit *SourceDag,
143144
const DagInit *DestDag,
@@ -349,7 +350,8 @@ static bool validateArgsTypes(const Init *Arg1, const Init *Arg2) {
349350
void CompressInstEmitter::createDagOperandMapping(
350351
const Record *Rec, StringMap<unsigned> &SourceOperands,
351352
StringMap<unsigned> &DestOperands, const DagInit *SourceDag,
352-
const DagInit *DestDag, IndexedMap<OpData> &SourceOperandMap) {
353+
const DagInit *DestDag, IndexedMap<OpData> &SourceOperandMap,
354+
bool HasSourceTiedOp) {
353355
for (unsigned I = 0; I < DestDag->getNumArgs(); ++I) {
354356
// Skip fixed immediates and registers, they were handled in
355357
// addDagOperandMapping.
@@ -368,7 +370,10 @@ void CompressInstEmitter::createDagOperandMapping(
368370
SourceOperands.find(SourceDag->getArgNameStr(I));
369371
if (It != SourceOperands.end()) {
370372
// Operand sharing the same name in the Dag should be mapped as tied.
371-
SourceOperandMap[I].TiedOpIdx = It->getValue();
373+
if (HasSourceTiedOp)
374+
SourceOperandMap[I + 1].TiedOpIdx = It->getValue() + 1;
375+
else
376+
SourceOperandMap[I].TiedOpIdx = It->getValue();
372377
if (!validateArgsTypes(SourceDag->getArg(It->getValue()),
373378
SourceDag->getArg(I)))
374379
PrintFatalError(Rec->getLoc(),
@@ -521,8 +526,10 @@ void CompressInstEmitter::evaluateCompressPat(const Record *Rec) {
521526

522527
StringMap<unsigned> SourceOperands;
523528
StringMap<unsigned> DestOperands;
529+
bool HasSourceTiedOp =
530+
SourceLastTiedOp != std::numeric_limits<unsigned int>::max();
524531
createDagOperandMapping(Rec, SourceOperands, DestOperands, SourceDag, DestDag,
525-
SourceOperandMap);
532+
SourceOperandMap, HasSourceTiedOp);
526533
// Create operand mapping between the source and destination instructions.
527534
createInstOperandMapping(Rec, SourceDag, DestDag, SourceOperandMap,
528535
DestOperandMap, SourceOperands, DestInst,

0 commit comments

Comments
 (0)