[llvm] [AMDGPU] Merge two V_CNDMASK instructions into V_DUAL_CNDMASK (PR #135007)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 9 07:00:09 PDT 2025
================
@@ -1459,13 +1482,73 @@ bool SIFoldOperandsImpl::tryConstantFoldOp(MachineInstr *MI) const {
return false;
}
+bool SIFoldOperandsImpl::shouldSwitchOperands(MachineRegisterInfo &MRI,
+ MachineInstr &MI,
+ const SIInstrInfo &TII) const {
+ auto allUses = MRI.use_nodbg_operands(MI.getOperand(5).getReg());
+ unsigned count = 0;
+
+ for (auto &Use : allUses) {
+ if (Use.getParent()->getOpcode() != AMDGPU::V_CNDMASK_B32_e64)
+ return false;
+ MachineOperand *Src0 =
+ TII.getNamedOperand(*Use.getParent(), AMDGPU::OpName::src0);
+ MachineOperand *Src1 =
+ TII.getNamedOperand(*Use.getParent(), AMDGPU::OpName::src1);
+
+ auto src0Imm = getImmOrMaterializedImm(*Src0);
+ auto src1Imm = getImmOrMaterializedImm(*Src1);
+
+ if (!src1Imm && src0Imm)
+ return false;
+ if (src1Imm && !src0Imm)
+ count++;
+ }
+ return (count >= 2);
----------------
jayfoad wrote:
It is probably still worth doing this if count == 1, to reduce code size.
https://github.com/llvm/llvm-project/pull/135007
More information about the llvm-commits
mailing list