Skip to content

Commit 52b33ff

Browse files
committed
[RISCV] Avoid toggling VL for hidden splat case in constant buildvector lowering
We have the analogous case in the single insert path. The reasoning here is that if the original VL fits in LMUL1, we'd prefer to clobber a few extra dead lanes than to force two VL toggles. VTYPE toggles are generally cheaper than VL toggles.
1 parent 68033aa commit 52b33ff

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3456,11 +3456,19 @@ static SDValue lowerBuildVectorOfConstants(SDValue Op, SelectionDAG &DAG,
34563456
(Sequence.size() * EltBitSize) <= 64) {
34573457
unsigned SeqLen = Sequence.size();
34583458
MVT ViaIntVT = MVT::getIntegerVT(EltBitSize * SeqLen);
3459-
MVT ViaVecVT = MVT::getVectorVT(ViaIntVT, NumElts / SeqLen);
34603459
assert((ViaIntVT == MVT::i16 || ViaIntVT == MVT::i32 ||
34613460
ViaIntVT == MVT::i64) &&
34623461
"Unexpected sequence type");
34633462

3463+
// If we can use the original VL with the modified element type, this
3464+
// means we only have a VTYPE toggle, not a VL toggle. TODO: Should this
3465+
// be moved into InsertVSETVLI?
3466+
const unsigned RequiredVL = NumElts / SeqLen;
3467+
const unsigned ViaVecLen =
3468+
(Subtarget.getRealMinVLen() >= ViaIntVT.getSizeInBits() * NumElts) ?
3469+
NumElts : RequiredVL;
3470+
MVT ViaVecVT = MVT::getVectorVT(ViaIntVT, ViaVecLen);
3471+
34643472
unsigned EltIdx = 0;
34653473
uint64_t EltMask = maskTrailingOnes<uint64_t>(EltBitSize);
34663474
uint64_t SplatValue = 0;
@@ -3494,6 +3502,10 @@ static SDValue lowerBuildVectorOfConstants(SDValue Op, SelectionDAG &DAG,
34943502
DAG.getUNDEF(ViaContainerVT),
34953503
DAG.getConstant(SplatValue, DL, XLenVT), ViaVL);
34963504
Splat = convertFromScalableVector(ViaVecVT, Splat, DAG, Subtarget);
3505+
if (ViaVecLen != RequiredVL)
3506+
Splat = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL,
3507+
MVT::getVectorVT(ViaIntVT, RequiredVL), Splat,
3508+
DAG.getConstant(0, DL, XLenVT));
34973509
return DAG.getBitcast(VT, Splat);
34983510
}
34993511
}

llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int-buildvec.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,8 @@ define void @buildvec_seq_v8i8_v4i16(ptr %x) {
518518
; CHECK-LABEL: buildvec_seq_v8i8_v4i16:
519519
; CHECK: # %bb.0:
520520
; CHECK-NEXT: li a1, 513
521-
; CHECK-NEXT: vsetivli zero, 4, e16, mf2, ta, ma
521+
; CHECK-NEXT: vsetivli zero, 8, e16, m1, ta, ma
522522
; CHECK-NEXT: vmv.v.x v8, a1
523-
; CHECK-NEXT: vsetivli zero, 8, e8, mf2, ta, ma
524523
; CHECK-NEXT: vse8.v v8, (a0)
525524
; CHECK-NEXT: ret
526525
store <8 x i8> <i8 1, i8 2, i8 1, i8 2, i8 1, i8 2, i8 undef, i8 2>, ptr %x
@@ -623,9 +622,8 @@ define void @buildvec_seq_v4i16_v2i32(ptr %x) {
623622
; CHECK-LABEL: buildvec_seq_v4i16_v2i32:
624623
; CHECK: # %bb.0:
625624
; CHECK-NEXT: li a1, -127
626-
; CHECK-NEXT: vsetivli zero, 2, e32, mf2, ta, ma
625+
; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, ma
627626
; CHECK-NEXT: vmv.v.x v8, a1
628-
; CHECK-NEXT: vsetivli zero, 4, e16, mf2, ta, ma
629627
; CHECK-NEXT: vse16.v v8, (a0)
630628
; CHECK-NEXT: ret
631629
store <4 x i16> <i16 -127, i16 -1, i16 -127, i16 -1>, ptr %x

0 commit comments

Comments
 (0)