[llvm] 74f5dd5 - [RISCV]Lower one active interleaved load to normal segmented load (#185602)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 11 03:08:38 PDT 2026
Author: Liao Chunyu
Date: 2026-03-11T18:08:32+08:00
New Revision: 74f5dd5c346a8282b21dd19fe720471a4c071a7d
URL: https://github.com/llvm/llvm-project/commit/74f5dd5c346a8282b21dd19fe720471a4c071a7d
DIFF: https://github.com/llvm/llvm-project/commit/74f5dd5c346a8282b21dd19fe720471a4c071a7d.diff
LOG: [RISCV]Lower one active interleaved load to normal segmented load (#185602)
There’s an optimization for deinterleave loads in
`RISCVTargetLowering::PerformDAGCombine`.
We can generate a normal segmented load and
let DAGCombine optimize it into vlse.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVInterleavedAccess.cpp
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-interleaved-access.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVInterleavedAccess.cpp b/llvm/lib/Target/RISCV/RISCVInterleavedAccess.cpp
index 528bbdf4c26c6..6e2626d7130b9 100644
--- a/llvm/lib/Target/RISCV/RISCVInterleavedAccess.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInterleavedAccess.cpp
@@ -214,12 +214,11 @@ bool RISCVTargetLowering::lowerInterleavedLoad(
assert(GapMask.getBitWidth() == Factor);
// We only support cases where the skipped fields are the trailing ones.
- // TODO: Lower to strided load if there is only a single active field.
- unsigned MaskFactor = GapMask.popcount();
- if (MaskFactor < 2 || !GapMask.isMask())
+ if (!GapMask.isMask())
return false;
IRBuilder<> Builder(Load);
+ unsigned MaskFactor = GapMask.popcount();
const DataLayout &DL = Load->getDataLayout();
auto *VTy = cast<FixedVectorType>(Shuffles[0]->getType());
auto *XLenTy = Builder.getIntNTy(Subtarget.getXLen());
@@ -235,7 +234,7 @@ bool RISCVTargetLowering::lowerInterleavedLoad(
return false;
CallInst *SegLoad = nullptr;
- if (MaskFactor < Factor) {
+ if (MaskFactor < Factor && MaskFactor != 1) {
// Lower to strided segmented load.
unsigned ScalarSizeInBytes = DL.getTypeStoreSize(VTy->getElementType());
Value *Stride = ConstantInt::get(XLenTy, Factor * ScalarSizeInBytes);
diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-interleaved-access.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-interleaved-access.ll
index 9b35860904f11..82419c23bc124 100644
--- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-interleaved-access.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-interleaved-access.ll
@@ -2465,3 +2465,14 @@ define {<4 x i32>, <4 x i32>, <4 x i32>} @maskedload_factor5_skip_fields(ptr %pt
ret {<4 x i32>, <4 x i32>, <4 x i32>} %res2
}
+define <4 x i8> @maskedload_factor5_one_active(ptr %ptr) {
+; CHECK-LABEL: maskedload_factor5_one_active:
+; CHECK: # %bb.0:
+; CHECK-NEXT: li a1, 5
+; CHECK-NEXT: vsetivli zero, 4, e8, mf4, ta, ma
+; CHECK-NEXT: vlse8.v v8, (a0), a1
+; CHECK-NEXT: ret
+ %interleaved.vec = tail call <20 x i8> @llvm.masked.load.v20i8.p0(ptr %ptr, <20 x i1> <i1 true, i1 false, i1 false, i1 false, i1 false, i1 true, i1 false, i1 false, i1 false, i1 false, i1 true, i1 false, i1 false, i1 false, i1 false, i1 true, i1 false, i1 false, i1 false, i1 false>, <20 x i8> poison)
+ %v0 = shufflevector <20 x i8> %interleaved.vec, <20 x i8> poison, <4 x i32> <i32 0, i32 5, i32 10, i32 15>
+ ret <4 x i8> %v0
+}
More information about the llvm-commits
mailing list