Skip to content

Commit 7b5cf52

Browse files
committed
[RISCV] Improve splatPartsI64WithVL for fixed vector constants where Hi and Lo are the same and the VL is constant.
If doubling the VL will fit in a vsetivli, use it. It will be cheap to change and cheap to change back. This improves codegen from D158896. Reviewed By: reames Differential Revision: https://reviews.llvm.org/D158896
1 parent 299b1b4 commit 7b5cf52

9 files changed

+987
-1565
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3559,18 +3559,29 @@ static SDValue splatPartsI64WithVL(const SDLoc &DL, MVT VT, SDValue Passthru,
35593559
if ((LoC >> 31) == HiC)
35603560
return DAG.getNode(RISCVISD::VMV_V_X_VL, DL, VT, Passthru, Lo, VL);
35613561

3562-
// If vl is equal to VLMAX and Hi constant is equal to Lo, we could use
3563-
// vmv.v.x whose EEW = 32 to lower it.
3564-
if (LoC == HiC && (isAllOnesConstant(VL) ||
3565-
(isa<RegisterSDNode>(VL) &&
3566-
cast<RegisterSDNode>(VL)->getReg() == RISCV::X0))) {
3567-
MVT InterVT = MVT::getVectorVT(MVT::i32, VT.getVectorElementCount() * 2);
3568-
// TODO: if vl <= min(VLMAX), we can also do this. But we could not
3569-
// access the subtarget here now.
3570-
auto InterVec = DAG.getNode(
3571-
RISCVISD::VMV_V_X_VL, DL, InterVT, DAG.getUNDEF(InterVT), Lo,
3572-
DAG.getRegister(RISCV::X0, MVT::i32));
3573-
return DAG.getNode(ISD::BITCAST, DL, VT, InterVec);
3562+
// If vl is equal to VLMAX or fits in 4 bits and Hi constant is equal to Lo,
3563+
// we could use vmv.v.x whose EEW = 32 to lower it. This allows us to use
3564+
// vlmax vsetvli or vsetivli to change the VL.
3565+
// FIXME: Support larger constants?
3566+
// FIXME: Support non-constant VLs by saturating?
3567+
if (LoC == HiC) {
3568+
SDValue NewVL;
3569+
if (isAllOnesConstant(VL) ||
3570+
(isa<RegisterSDNode>(VL) &&
3571+
cast<RegisterSDNode>(VL)->getReg() == RISCV::X0))
3572+
NewVL = DAG.getRegister(RISCV::X0, MVT::i32);
3573+
else if (isa<ConstantSDNode>(VL) &&
3574+
isUInt<4>(cast<ConstantSDNode>(VL)->getZExtValue()))
3575+
NewVL = DAG.getNode(ISD::ADD, DL, VL.getValueType(), VL, VL);
3576+
3577+
if (NewVL) {
3578+
MVT InterVT =
3579+
MVT::getVectorVT(MVT::i32, VT.getVectorElementCount() * 2);
3580+
auto InterVec = DAG.getNode(RISCVISD::VMV_V_X_VL, DL, InterVT,
3581+
DAG.getUNDEF(InterVT), Lo,
3582+
DAG.getRegister(RISCV::X0, MVT::i32));
3583+
return DAG.getNode(ISD::BITCAST, DL, VT, InterVec);
3584+
}
35743585
}
35753586
}
35763587

0 commit comments

Comments
 (0)