Skip to content

Commit e7f9a83

Browse files
committed
[RISCV] Replace NoX0 SDNodeXForm with a ComplexPattern to do the selection of the VL operand.
I think this is a more standard way of doing this. Reviewed By: rogfer01 Differential Revision: https://reviews.llvm.org/D95833
1 parent 6bae597 commit e7f9a83

File tree

3 files changed

+114
-104
lines changed

3 files changed

+114
-104
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,23 @@ bool RISCVDAGToDAGISel::MatchSLLIUW(SDNode *N) const {
10111011
return (VC1 >> VC2) == UINT64_C(0xFFFFFFFF);
10121012
}
10131013

1014+
// X0 has special meaning for vsetvl/vsetvli.
1015+
// rd | rs1 | AVL value | Effect on vl
1016+
//--------------------------------------------------------------
1017+
// !X0 | X0 | VLMAX | Set vl to VLMAX
1018+
// X0 | X0 | Value in vl | Keep current vl, just change vtype.
1019+
bool RISCVDAGToDAGISel::selectVLOp(SDValue N, SDValue &VL) {
1020+
// If the VL value is a constant 0, manually select it to an ADDI with 0
1021+
// immediate to prevent the default selection path from matching it to X0.
1022+
auto *C = dyn_cast<ConstantSDNode>(N);
1023+
if (C && C->isNullValue())
1024+
VL = SDValue(selectImm(CurDAG, SDLoc(N), 0, Subtarget->getXLenVT()), 0);
1025+
else
1026+
VL = N;
1027+
1028+
return true;
1029+
}
1030+
10141031
bool RISCVDAGToDAGISel::selectVSplat(SDValue N, SDValue &SplatVal) {
10151032
if (N.getOpcode() != ISD::SPLAT_VECTOR &&
10161033
N.getOpcode() != RISCVISD::SPLAT_VECTOR_I64)

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class RISCVDAGToDAGISel : public SelectionDAGISel {
5353
bool MatchSROIW(SDNode *N) const;
5454
bool MatchSLLIUW(SDNode *N) const;
5555

56+
bool selectVLOp(SDValue N, SDValue &VL);
57+
5658
bool selectVSplat(SDValue N, SDValue &SplatVal);
5759
bool selectVSplatSimm5(SDValue N, SDValue &SplatVal);
5860
bool selectVSplatUimm5(SDValue N, SDValue &SplatVal);

0 commit comments

Comments
 (0)