[llvm] [RISCV][IA] Use strided load for one active deinterleaveN(load) (PR #148892)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 16 09:50:29 PDT 2025


================
@@ -243,20 +243,44 @@ bool RISCVTargetLowering::lowerDeinterleaveIntrinsicToLoad(
   assert(LI->isSimple());
   IRBuilder<> Builder(LI);
 
-  Value *FirstActive =
-      *llvm::find_if(DeinterleaveValues, [](Value *V) { return V != nullptr; });
-  VectorType *ResVTy = cast<VectorType>(FirstActive->getType());
+  auto FirstActiveItr =
+      llvm::find_if(DeinterleaveValues, [](Value *V) { return V != nullptr; });
+  VectorType *ResVTy = cast<VectorType>((*FirstActiveItr)->getType());
 
   const DataLayout &DL = LI->getDataLayout();
-
   if (!isLegalInterleavedAccessType(ResVTy, Factor, LI->getAlign(),
                                     LI->getPointerAddressSpace(), DL))
     return false;
 
-  Value *Return;
   Type *PtrTy = LI->getPointerOperandType();
   Type *XLenTy = Type::getIntNTy(LI->getContext(), Subtarget.getXLen());
 
+  // If the segment load is going to be performed segment at a time anyways
+  // and there's only one element used, use a strided load instead.  This
+  // will be equally fast, and create less vector register pressure.
+  if (!Subtarget.hasOptimizedSegmentLoadStore(Factor) &&
+      1 == llvm::count_if(DeinterleaveValues,
+                          [](Value *V) { return V != nullptr; })) {
----------------
lukel97 wrote:

Nit
```suggestion
      llvm::count_if(DeinterleaveValues,
                          [](Value *V) { return V != nullptr; }) == 1) {
```

https://github.com/llvm/llvm-project/pull/148892


More information about the llvm-commits mailing list