Skip to content

Commit a0a904e

Browse files
authored
[RISCV] Collect shuffle mask for the lane not by createSequentialMask (#129830)
If there are the shuffle mask <1, u, u, u, 2, u, u, u> with factor 4. we should have the shuffle mask <1, 2> for lane 0 and <u, u> for lane 1, and so on. Since we use createSequentialMask to create the shuffle mask, the shuffle mask for lane 1 would be <u, 0>(dervied from <u, u+1>). This leads to poor code generation.
1 parent 6eefadd commit a0a904e

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23110,12 +23110,18 @@ bool RISCVTargetLowering::lowerInterleavedStore(StoreInst *SI,
2311023110
{VTy, SI->getPointerOperandType(), XLenTy});
2311123111

2311223112
SmallVector<Value *, 10> Ops;
23113+
SmallVector<int, 16> NewShuffleMask;
2311323114

2311423115
for (unsigned i = 0; i < Factor; i++) {
23116+
// Collect shuffle mask for this lane.
23117+
for (unsigned j = 0; j < VTy->getNumElements(); j++)
23118+
NewShuffleMask.push_back(Mask[i + Factor * j]);
23119+
2311523120
Value *Shuffle = Builder.CreateShuffleVector(
23116-
SVI->getOperand(0), SVI->getOperand(1),
23117-
createSequentialMask(Mask[i], VTy->getNumElements(), 0));
23121+
SVI->getOperand(0), SVI->getOperand(1), NewShuffleMask);
2311823122
Ops.push_back(Shuffle);
23123+
23124+
NewShuffleMask.clear();
2311923125
}
2312023126
// This VL should be OK (should be executable in one vsseg instruction,
2312123127
// potentially under larger LMULs) because we checked that the fixed vector

llvm/test/CodeGen/RISCV/rvv/fixed-vectors-interleaved-access.ll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,16 +1394,12 @@ define void @store_factor4_one_active_fullwidth(ptr %ptr, <16 x i32> %v) {
13941394
ret void
13951395
}
13961396

1397-
; TODO: This could be a vslidedown followed by a strided store
13981397
define void @store_factor4_one_active_slidedown(ptr %ptr, <4 x i32> %v) {
13991398
; CHECK-LABEL: store_factor4_one_active_slidedown:
14001399
; CHECK: # %bb.0:
14011400
; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, ma
1402-
; CHECK-NEXT: vslidedown.vi v9, v8, 1
1403-
; CHECK-NEXT: vslideup.vi v10, v8, 1
1404-
; CHECK-NEXT: vmv.v.v v11, v10
1405-
; CHECK-NEXT: vmv.v.v v12, v10
1406-
; CHECK-NEXT: vsseg4e32.v v9, (a0)
1401+
; CHECK-NEXT: vslidedown.vi v8, v8, 1
1402+
; CHECK-NEXT: vsseg4e32.v v8, (a0)
14071403
; CHECK-NEXT: ret
14081404
%v0 = shufflevector <4 x i32> %v, <4 x i32> poison, <16 x i32> <i32 1, i32 undef, i32 undef, i32 undef, i32 2, i32 undef, i32 undef, i32 undef, i32 3, i32 undef, i32 undef, i32 undef, i32 4, i32 undef, i32 undef, i32 undef>
14091405
store <16 x i32> %v0, ptr %ptr

0 commit comments

Comments
 (0)