[llvm] [RISCV] Sink vp.splat operands of VP intrinsic. (PR #133245)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 21 02:20:09 PDT 2025
================
@@ -2837,39 +2837,41 @@ bool RISCVTTIImpl::isProfitableToSinkOperands(
if (!ST->sinkSplatOperands())
return false;
- for (auto OpIdx : enumerate(I->operands())) {
- if (!canSplatOperand(I, OpIdx.index()))
- continue;
-
- Instruction *Op = dyn_cast<Instruction>(OpIdx.value().get());
+ for (auto &U : I->operands()) {
+ auto *Op = dyn_cast<Instruction>(U.get());
// Make sure we are not already sinking this operand
if (!Op || any_of(Ops, [&](Use *U) { return U->get() == Op; }))
continue;
- // We are looking for a splat that can be sunk.
- if (!match(Op, m_Shuffle(m_InsertElt(m_Undef(), m_Value(), m_ZeroInt()),
+ // We are looking for a splat/vp.splat that can be sunk.
+ bool IsVPSplat = match(Op, m_Intrinsic<Intrinsic::experimental_vp_splat>(
+ m_Value(), m_Value(), m_Value()));
+ if (!IsVPSplat &&
+ !match(Op, m_Shuffle(m_InsertElt(m_Undef(), m_Value(), m_ZeroInt()),
m_Undef(), m_ZeroMask())))
continue;
// Don't sink i1 splats.
if (cast<VectorType>(Op->getType())->getElementType()->isIntegerTy(1))
continue;
- // All uses of the shuffle should be sunk to avoid duplicating it across gpr
- // and vector registers
- for (Use &U : Op->uses()) {
- Instruction *Insn = cast<Instruction>(U.getUser());
- if (!canSplatOperand(Insn, U.getOperandNo()))
- return false;
- }
+ // All uses of the splat/vp.splat should be sunk to avoid duplicating it
+ // across gpr and vector registers
+ if (any_of(Op->uses(), [this](Use &U) {
+ return !canSplatOperand(cast<Instruction>(U.getUser()),
+ U.getOperandNo());
+ }))
+ continue;
----------------
lukel97 wrote:
Can this be left as its original form? I find the for loop version a bit easier to read
https://github.com/llvm/llvm-project/pull/133245
More information about the llvm-commits
mailing list