[AMDGPU] SIFoldOperands: refactor tryFoldCndMask with early-outs. NFC.

This commit is contained in:
Jay Foad 2021-04-08 13:03:20 +01:00
parent 140757bfaa
commit 94a6fe43de
1 changed files with 29 additions and 27 deletions

View File

@ -1149,35 +1149,37 @@ static bool tryConstantFoldOp(MachineRegisterInfo &MRI,
static bool tryFoldCndMask(const SIInstrInfo *TII,
MachineInstr *MI) {
unsigned Opc = MI->getOpcode();
if (Opc != AMDGPU::V_CNDMASK_B32_e32 && Opc != AMDGPU::V_CNDMASK_B32_e64 &&
Opc != AMDGPU::V_CNDMASK_B64_PSEUDO)
return false;
if (Opc == AMDGPU::V_CNDMASK_B32_e32 ||
Opc == AMDGPU::V_CNDMASK_B32_e64 ||
Opc == AMDGPU::V_CNDMASK_B64_PSEUDO) {
const MachineOperand *Src0 = TII->getNamedOperand(*MI, AMDGPU::OpName::src0);
const MachineOperand *Src1 = TII->getNamedOperand(*MI, AMDGPU::OpName::src1);
int Src1ModIdx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src1_modifiers);
int Src0ModIdx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src0_modifiers);
if (Src1->isIdenticalTo(*Src0) &&
(Src1ModIdx == -1 || !MI->getOperand(Src1ModIdx).getImm()) &&
(Src0ModIdx == -1 || !MI->getOperand(Src0ModIdx).getImm())) {
LLVM_DEBUG(dbgs() << "Folded " << *MI << " into ");
auto &NewDesc =
TII->get(Src0->isReg() ? (unsigned)AMDGPU::COPY : getMovOpc(false));
int Src2Idx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src2);
if (Src2Idx != -1)
MI->RemoveOperand(Src2Idx);
MI->RemoveOperand(AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src1));
if (Src1ModIdx != -1)
MI->RemoveOperand(Src1ModIdx);
if (Src0ModIdx != -1)
MI->RemoveOperand(Src0ModIdx);
mutateCopyOp(*MI, NewDesc);
LLVM_DEBUG(dbgs() << *MI);
return true;
}
}
MachineOperand *Src0 = TII->getNamedOperand(*MI, AMDGPU::OpName::src0);
MachineOperand *Src1 = TII->getNamedOperand(*MI, AMDGPU::OpName::src1);
if (!Src1->isIdenticalTo(*Src0))
return false;
return false;
int Src1ModIdx =
AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src1_modifiers);
int Src0ModIdx =
AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src0_modifiers);
if ((Src1ModIdx != -1 && MI->getOperand(Src1ModIdx).getImm() != 0) ||
(Src0ModIdx != -1 && MI->getOperand(Src0ModIdx).getImm() != 0))
return false;
LLVM_DEBUG(dbgs() << "Folded " << *MI << " into ");
auto &NewDesc =
TII->get(Src0->isReg() ? (unsigned)AMDGPU::COPY : getMovOpc(false));
int Src2Idx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src2);
if (Src2Idx != -1)
MI->RemoveOperand(Src2Idx);
MI->RemoveOperand(AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src1));
if (Src1ModIdx != -1)
MI->RemoveOperand(Src1ModIdx);
if (Src0ModIdx != -1)
MI->RemoveOperand(Src0ModIdx);
mutateCopyOp(*MI, NewDesc);
LLVM_DEBUG(dbgs() << *MI);
return true;
}
void SIFoldOperands::foldInstOperand(MachineInstr &MI,