Skip to content

Commit 870f41b

Browse files
committed
[RISCV] Combine (vp.splice (insert_elt poison, scalar, 0), vec, 0, mask, 1, vl) -> (vslideup_vl undef, vec, scalar, mask, vl)
1 parent bb51c5d commit 870f41b

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17601,6 +17601,36 @@ static SDValue performFP_TO_INT_SATCombine(SDNode *N,
1760117601
return DAG.getSelectCC(DL, Src, Src, ZeroInt, FpToInt, ISD::CondCode::SETUO);
1760217602
}
1760317603

17604+
static SDValue performVSLIDEUPOrDOWNCombine(SDNode *N, SelectionDAG &DAG) {
17605+
assert((N->getOpcode() == RISCVISD::VSLIDEUP_VL ||
17606+
N->getOpcode() == RISCVISD::VSLIDEDOWN_VL) &&
17607+
"Unexpected opcode");
17608+
17609+
using namespace SDPatternMatch;
17610+
17611+
SDLoc DL(N);
17612+
SDValue Vec;
17613+
// (vslideup_vl/vslidedown_vl undef, vec, 0, mask, vl, policy) -> (vec)
17614+
if (sd_match(N, m_Node(N->getOpcode(), m_Undef(), m_Value(Vec), m_Zero(),
17615+
m_Value(), m_Value(), m_Value())))
17616+
return Vec;
17617+
17618+
SDValue FirstEle, Mask, VL;
17619+
// (vslideup_vl (insert_ele poison first, 0), vec, 1, mask, vl, policy)
17620+
// -> (vslide1up_vl/vfslide1up_vl undef, vec, first, mask, vl)
17621+
if (sd_match(N, m_Node(RISCVISD::VSLIDEUP_VL,
17622+
m_InsertElt(m_Poison(), m_Value(FirstEle), m_Zero()),
17623+
m_Value(Vec), m_One(), m_Value(Mask), m_Value(VL),
17624+
m_Value()))) {
17625+
EVT VT = Vec.getValueType();
17626+
return DAG.getNode(VT.isFloatingPoint() ? RISCVISD::VFSLIDE1UP_VL
17627+
: RISCVISD::VSLIDE1UP_VL,
17628+
DL, VT, DAG.getUNDEF(VT), Vec, FirstEle, Mask, VL);
17629+
}
17630+
17631+
return SDValue();
17632+
}
17633+
1760417634
// Combine (bitreverse (bswap X)) to the BREV8 GREVI encoding if the type is
1760517635
// smaller than XLenVT.
1760617636
static SDValue performBITREVERSECombine(SDNode *N, SelectionDAG &DAG,
@@ -19881,6 +19911,9 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
1988119911

1988219912
return SDValue();
1988319913
}
19914+
case RISCVISD::VSLIDEUP_VL:
19915+
case RISCVISD::VSLIDEDOWN_VL:
19916+
return performVSLIDEUPOrDOWNCombine(N, DAG);
1988419917
case ISD::BITREVERSE:
1988519918
return performBITREVERSECombine(N, DAG, Subtarget);
1988619919
case ISD::FP_TO_SINT:

llvm/test/CodeGen/RISCV/rvv/vp-splice.ll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,27 @@ define <vscale x 2 x float> @test_vp_splice_nxv2f32_masked(<vscale x 2 x float>
286286
%v = call <vscale x 2 x float> @llvm.experimental.vp.splice.nxv2f32(<vscale x 2 x float> %va, <vscale x 2 x float> %vb, i32 5, <vscale x 2 x i1> %mask, i32 %evla, i32 %evlb)
287287
ret <vscale x 2 x float> %v
288288
}
289+
290+
define <vscale x 2 x i32> @test_vp_splice_nxv2i32_with_firstelt(i32 %first, <vscale x 2 x i32> %vb, <vscale x 2 x i1> %mask, i32 zeroext %evl) {
291+
; CHECK-LABEL: test_vp_splice_nxv2i32_with_firstelt:
292+
; CHECK: # %bb.0:
293+
; CHECK-NEXT: vsetvli zero, a1, e32, m1, ta, ma
294+
; CHECK-NEXT: vslide1up.vx v9, v8, a0, v0.t
295+
; CHECK-NEXT: vmv.v.v v8, v9
296+
; CHECK-NEXT: ret
297+
%va = insertelement <vscale x 2 x i32> poison, i32 %first, i32 0
298+
%v = call <vscale x 2 x i32> @llvm.experimental.vp.splice.nxv2i32(<vscale x 2 x i32> %va, <vscale x 2 x i32> %vb, i32 0, <vscale x 2 x i1> %mask, i32 1, i32 %evl)
299+
ret <vscale x 2 x i32> %v
300+
}
301+
302+
define <vscale x 2 x float> @test_vp_splice_nxv2f32_with_firstelt(float %first, <vscale x 2 x float> %vb, <vscale x 2 x i1> %mask, i32 zeroext %evl) {
303+
; CHECK-LABEL: test_vp_splice_nxv2f32_with_firstelt:
304+
; CHECK: # %bb.0:
305+
; CHECK-NEXT: vsetvli zero, a0, e32, m1, ta, ma
306+
; CHECK-NEXT: vfslide1up.vf v9, v8, fa0, v0.t
307+
; CHECK-NEXT: vmv.v.v v8, v9
308+
; CHECK-NEXT: ret
309+
%va = insertelement <vscale x 2 x float> poison, float %first, i32 0
310+
%v = call <vscale x 2 x float> @llvm.experimental.vp.splice.nxv2f32(<vscale x 2 x float> %va, <vscale x 2 x float> %vb, i32 0, <vscale x 2 x i1> %mask, i32 1, i32 %evl)
311+
ret <vscale x 2 x float> %v
312+
}

0 commit comments

Comments
 (0)