[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:56 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?
----------------
lukel97 wrote:
I just did a quick check and I think we still match even on all-disabled VP intrinsics, e.g.:
```llvm
define <vscale x 8 x i32> @f(<vscale x 8 x i32> %a, i32 zeroext %b, i32 zeroext %evl) {
%splat = tail call <vscale x 8 x i32> @llvm.experimental.vp.splat.nxv8i32(i32 %b, <vscale x 8 x i1> splat(i1 false), i32 0)
%add = call <vscale x 8 x i32> @llvm.vp.add(<vscale x 8 x i32> %a, <vscale x 8 x i32> %splat, <vscale x 8 x i1> splat (i1 true), i32 %evl)
ret <vscale x 8 x i32> %add
}
```
Still matches to
```asm
f: # @f
.cfi_startproc
# %bb.0:
vsetvli zero, a1, e32, m4, ta, ma
vadd.vx v8, v8, a0
ret
```
https://github.com/llvm/llvm-project/pull/133245
More information about the llvm-commits
mailing list