Skip to content

Commit 5f243b3

Browse files
authored
AMDGPU: Generalize instruction shrinking code (#93810)
Try to avoid referring to specific operand names, except in the special case. The special case for hasNamedOperand(Op32, sdst) seems to have been dead code.
1 parent ce5b371 commit 5f243b3

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4486,46 +4486,46 @@ static void copyFlagsToImplicitVCC(MachineInstr &MI,
44864486
MachineInstr *SIInstrInfo::buildShrunkInst(MachineInstr &MI,
44874487
unsigned Op32) const {
44884488
MachineBasicBlock *MBB = MI.getParent();
4489+
4490+
const MCInstrDesc &Op32Desc = get(Op32);
44894491
MachineInstrBuilder Inst32 =
4490-
BuildMI(*MBB, MI, MI.getDebugLoc(), get(Op32))
4492+
BuildMI(*MBB, MI, MI.getDebugLoc(), Op32Desc)
44914493
.setMIFlags(MI.getFlags());
44924494

44934495
// Add the dst operand if the 32-bit encoding also has an explicit $vdst.
44944496
// For VOPC instructions, this is replaced by an implicit def of vcc.
4495-
if (AMDGPU::hasNamedOperand(Op32, AMDGPU::OpName::vdst)) {
4496-
// dst
4497-
Inst32.add(MI.getOperand(0));
4498-
} else if (AMDGPU::hasNamedOperand(Op32, AMDGPU::OpName::sdst)) {
4499-
// VOPCX instructions won't be writing to an explicit dst, so this should
4500-
// not fail for these instructions.
4501-
assert(((MI.getOperand(0).getReg() == AMDGPU::VCC) ||
4502-
(MI.getOperand(0).getReg() == AMDGPU::VCC_LO)) &&
4503-
"Unexpected case");
4504-
}
4505-
4506-
Inst32.add(*getNamedOperand(MI, AMDGPU::OpName::src0));
45074497

4508-
const MachineOperand *Src1 = getNamedOperand(MI, AMDGPU::OpName::src1);
4509-
if (Src1)
4510-
Inst32.add(*Src1);
4498+
// We assume the defs of the shrunk opcode are in the same order, and the
4499+
// shrunk opcode loses the last def (SGPR def, in the VOP3->VOPC case).
4500+
for (int I = 0, E = Op32Desc.getNumDefs(); I != E; ++I)
4501+
Inst32.add(MI.getOperand(I));
45114502

45124503
const MachineOperand *Src2 = getNamedOperand(MI, AMDGPU::OpName::src2);
45134504

4514-
if (Src2) {
4515-
int Op32Src2Idx = AMDGPU::getNamedOperandIdx(Op32, AMDGPU::OpName::src2);
4516-
if (Op32Src2Idx != -1) {
4517-
Inst32.add(*Src2);
4518-
} else {
4519-
// In the case of V_CNDMASK_B32_e32, the explicit operand src2 is
4520-
// replaced with an implicit read of vcc or vcc_lo. The implicit read
4521-
// of vcc was already added during the initial BuildMI, but we
4522-
// 1) may need to change vcc to vcc_lo to preserve the original register
4523-
// 2) have to preserve the original flags.
4524-
fixImplicitOperands(*Inst32);
4525-
copyFlagsToImplicitVCC(*Inst32, *Src2);
4505+
int Idx = MI.getNumExplicitDefs();
4506+
for (const MachineOperand &Use : MI.explicit_uses()) {
4507+
int OpTy = MI.getDesc().operands()[Idx++].OperandType;
4508+
if (OpTy == AMDGPU::OPERAND_INPUT_MODS || OpTy == MCOI::OPERAND_IMMEDIATE)
4509+
continue;
4510+
4511+
if (&Use == Src2) {
4512+
if (AMDGPU::getNamedOperandIdx(Op32, AMDGPU::OpName::src2) == -1) {
4513+
// In the case of V_CNDMASK_B32_e32, the explicit operand src2 is
4514+
// replaced with an implicit read of vcc or vcc_lo. The implicit read
4515+
// of vcc was already added during the initial BuildMI, but we
4516+
// 1) may need to change vcc to vcc_lo to preserve the original register
4517+
// 2) have to preserve the original flags.
4518+
fixImplicitOperands(*Inst32);
4519+
copyFlagsToImplicitVCC(*Inst32, *Src2);
4520+
continue;
4521+
}
45264522
}
4523+
4524+
Inst32.add(Use);
45274525
}
45284526

4527+
// FIXME: Losing implicit operands
4528+
45294529
return Inst32;
45304530
}
45314531

0 commit comments

Comments
 (0)