[llvm] [RISCV] Consider all subvector extracts within a single VREG cheap (PR #81032)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 7 19:50:00 PST 2024
================
@@ -2173,19 +2173,35 @@ bool RISCVTargetLowering::isExtractSubvectorCheap(EVT ResVT, EVT SrcVT,
if (ResVT.isScalableVector() || SrcVT.isScalableVector())
return false;
+ EVT EltVT = ResVT.getVectorElementType();
+ if (EltVT != SrcVT.getVectorElementType())
+ return false;
+
+ // The smallest type we can slide is i8.
+ // TODO: We can extract index 0 from a mask vector without a slide.
+ if (EltVT == MVT::i1)
+ return false;
+
unsigned ResElts = ResVT.getVectorNumElements();
unsigned SrcElts = SrcVT.getVectorNumElements();
+ unsigned MinVLen = Subtarget.getRealMinVLen();
+ unsigned MinVLMAX = MinVLen / EltVT.getSizeInBits();
+
+ // If we're extracting only data from the first VLEN bits of the source
+ // then we can always do this with an m1 vslidedown.vx. Restricting the
+ // Index ensures we can use a vslidedown.vi.
+ // TODO: We can generalize this when the exact VLEN is known.
+ if (Index + ResElts <= MinVLMAX && Index < 31)
+ return true;
+
// Convervatively only handle extracting half of a vector.
- // TODO: Relax this.
+ // TODO: For sizes which aren't multiples of VLEN sizes, this may not be
+ // a cheap extract. However, this case is important in practice for
+ // shuffled extracts of longer vectors. How resolve?
if ((ResElts * 2) != SrcElts)
return false;
- // The smallest type we can slide is i8.
- // TODO: We can extract index 0 from a mask vector without a slide.
- if (ResVT.getVectorElementType() == MVT::i1)
- return false;
-
// Slide can support arbitrary index, but we only treat vslidedown.vi as
// cheap.
if (Index >= 32)
----------------
lukel97 wrote:
Nit, could we move this check up so we don't need to repeat it on line 2195?
https://github.com/llvm/llvm-project/pull/81032
More information about the llvm-commits
mailing list