[llvm] [RISCV] Sink vp.splat operands of VP intrinsic. (PR #133245)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 14 07:52:55 PDT 2025
================
@@ -2837,39 +2837,43 @@ 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.
+ // FIXME: Should we care about the poison value of inactive elements in
+ // vp.splat?
+ 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;
----------------
lukel97 wrote:
Can we match this as
```suggestion
if (!match(Op, m_CombineOr(m_Shuffle(m_InsertElt(m_Undef(), m_Value(Val), m_ZeroInt()),
m_Undef(), m_ZeroMask())),
m_Intrinsic<Intrinsic::experimental_vp_splat>(
m_Value(Val), m_Value(), m_Value())))
continue;
```
And then below we can replace InsertElt with Val. That way it would work with both vp and non-vp splats?
https://github.com/llvm/llvm-project/pull/133245
More information about the llvm-commits
mailing list