[llvm] 94a6fe4 - [AMDGPU] SIFoldOperands: refactor tryFoldCndMask with early-outs. NFC.
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 8 05:16:29 PDT 2021
Author: Jay Foad
Date: 2021-04-08T13:16:07+01:00
New Revision: 94a6fe43de4583038e137f2fcbe634c174af5662
URL: https://github.com/llvm/llvm-project/commit/94a6fe43de4583038e137f2fcbe634c174af5662
DIFF: https://github.com/llvm/llvm-project/commit/94a6fe43de4583038e137f2fcbe634c174af5662.diff
LOG: [AMDGPU] SIFoldOperands: refactor tryFoldCndMask with early-outs. NFC.
Added:
Modified:
llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
index b5409330a8c5..482f5b4e97dd 100644
--- a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
+++ b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
@@ -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,
More information about the llvm-commits
mailing list