Skip to content

Commit a405a78

Browse files
committed
[RISCV] Replace vmv.s.x -> vmv.v.i DAG combine with patterns. NFC
We can also remove the combine that reduces LMUL, since we've removed the LMUL variants in #71501.
1 parent a1dad85 commit a405a78

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15223,9 +15223,7 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
1522315223
return Src.getOperand(0);
1522415224
// TODO: Use insert_subvector/extract_subvector to change widen/narrow?
1522515225
}
15226-
[[fallthrough]];
15227-
}
15228-
case RISCVISD::VMV_S_X_VL: {
15226+
1522915227
const MVT VT = N->getSimpleValueType(0);
1523015228
SDValue Passthru = N->getOperand(0);
1523115229
SDValue Scalar = N->getOperand(1);
@@ -15243,15 +15241,6 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
1524315241
DAG.getConstant(0, DL, XLenVT));
1524415242
return Result;
1524515243
}
15246-
15247-
// We use a vmv.v.i if possible. We limit this to LMUL1. LMUL2 or
15248-
// higher would involve overly constraining the register allocator for
15249-
// no purpose.
15250-
if (ConstantSDNode *Const = dyn_cast<ConstantSDNode>(Scalar);
15251-
Const && !Const->isZero() && isInt<5>(Const->getSExtValue()) &&
15252-
VT.bitsLE(getLMUL1VT(VT)) && Passthru.isUndef())
15253-
return DAG.getNode(RISCVISD::VMV_V_X_VL, DL, VT, Passthru, Scalar, VL);
15254-
1525515244
break;
1525615245
}
1525715246
case ISD::INTRINSIC_VOID:

llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2758,11 +2758,27 @@ foreach mti = AllMasks in {
27582758

27592759
// 16. Vector Permutation Instructions
27602760

2761+
def simm5_nonzero : ImmLeaf<XLenVT, [{return Imm != 0 && isInt<5>(Imm);}]>;
2762+
27612763
// 16.1. Integer Scalar Move Instructions
27622764
// 16.4. Vector Register Gather Instruction
27632765
foreach vti = AllIntegerVectors in {
27642766
let Predicates = GetVTypePredicates<vti>.Predicates in {
27652767
defvar isGroup = !isa<GroupVTypeInfo>(vti);
2768+
2769+
// Use vmv.v.i if we're inserting into undef and the scalar fits into simm5
2770+
// (and also isn't 0, since we could then just use x0)
2771+
defvar pseudoVIInstr = !if(isGroup,
2772+
PseudoVMV_V_I_M1,
2773+
!cast<Instruction>("PseudoVMV_V_I_" # vti.LMul.MX));
2774+
defvar pseudoVI = (pseudoVIInstr (IMPLICIT_DEF), simm5:$imm, GPR:$vl,
2775+
vti.Log2SEW, TU_MU);
2776+
def : Pat<(vti.Vector (riscv_vmv_s_x_vl (vti.Vector undef),
2777+
simm5_nonzero:$imm,
2778+
VLOpFrag)),
2779+
!if(isGroup, (INSERT_SUBREG (IMPLICIT_DEF), pseudoVI, sub_vrm1_0),
2780+
pseudoVI)>;
2781+
27662782
defvar merge = !if(isGroup,
27672783
(!cast<GroupVTypeInfo>(vti).VectorM1
27682784
(EXTRACT_SUBREG $merge, sub_vrm1_0)),
@@ -2776,7 +2792,6 @@ foreach vti = AllIntegerVectors in {
27762792
!if(isGroup, (INSERT_SUBREG $merge, pseudoVMV, sub_vrm1_0),
27772793
pseudoVMV)>;
27782794

2779-
27802795
def : Pat<(vti.Vector (riscv_vrgather_vv_vl vti.RegClass:$rs2,
27812796
vti.RegClass:$rs1,
27822797
vti.RegClass:$merge,

0 commit comments

Comments
 (0)