Skip to content

Commit 12af9c8

Browse files
committed
[RISCV] Extract a utility for computing bounds on VLMAX [nfc]
Simplifying an upcoming change...
1 parent 71ba8bb commit 12af9c8

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,6 +2624,25 @@ SDValue RISCVTargetLowering::computeVLMax(MVT VecVT, const SDLoc &DL,
26242624
VecVT.getVectorElementCount());
26252625
}
26262626

2627+
std::pair<unsigned, unsigned>
2628+
RISCVTargetLowering::computeVLMAXBounds(MVT VecVT,
2629+
const RISCVSubtarget &Subtarget) {
2630+
assert(VecVT.isScalableVector() && "Expected scalable vector");
2631+
2632+
unsigned EltSize = VecVT.getScalarSizeInBits();
2633+
unsigned MinSize = VecVT.getSizeInBits().getKnownMinValue();
2634+
2635+
unsigned VectorBitsMax = Subtarget.getRealMaxVLen();
2636+
unsigned MaxVLMAX =
2637+
RISCVTargetLowering::computeVLMAX(VectorBitsMax, EltSize, MinSize);
2638+
2639+
unsigned VectorBitsMin = Subtarget.getRealMinVLen();
2640+
unsigned MinVLMAX =
2641+
RISCVTargetLowering::computeVLMAX(VectorBitsMin, EltSize, MinSize);
2642+
2643+
return std::make_pair(MinVLMAX, MaxVLMAX);
2644+
}
2645+
26272646
// The state of RVV BUILD_VECTOR and VECTOR_SHUFFLE lowering is that very few
26282647
// of either is (currently) supported. This can get us into an infinite loop
26292648
// where we try to lower a BUILD_VECTOR as a VECTOR_SHUFFLE as a BUILD_VECTOR
@@ -8123,16 +8142,8 @@ static SDValue lowerVectorIntrinsicScalars(SDValue Op, SelectionDAG &DAG,
81238142

81248143
// Optimize for constant AVL
81258144
if (isa<ConstantSDNode>(AVL)) {
8126-
unsigned EltSize = VT.getScalarSizeInBits();
8127-
unsigned MinSize = VT.getSizeInBits().getKnownMinValue();
8128-
8129-
unsigned VectorBitsMax = Subtarget.getRealMaxVLen();
8130-
unsigned MaxVLMAX =
8131-
RISCVTargetLowering::computeVLMAX(VectorBitsMax, EltSize, MinSize);
8132-
8133-
unsigned VectorBitsMin = Subtarget.getRealMinVLen();
8134-
unsigned MinVLMAX =
8135-
RISCVTargetLowering::computeVLMAX(VectorBitsMin, EltSize, MinSize);
8145+
const auto [MinVLMAX, MaxVLMAX] =
8146+
RISCVTargetLowering::computeVLMAXBounds(VT, Subtarget);
81368147

81378148
uint64_t AVLInt = cast<ConstantSDNode>(AVL)->getZExtValue();
81388149
if (AVLInt <= MinVLMAX) {

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,13 @@ class RISCVTargetLowering : public TargetLowering {
744744
// The following equations have been reordered to prevent loss of precision
745745
// when calculating fractional LMUL.
746746
return ((VectorBits / EltSize) * MinSize) / RISCV::RVVBitsPerBlock;
747-
};
747+
}
748+
749+
// Return inclusive (low, high) bounds on the value of VLMAX for the
750+
// given scalable container type given known bounds on VLEN.
751+
static std::pair<unsigned, unsigned>
752+
computeVLMAXBounds(MVT ContainerVT, const RISCVSubtarget &Subtarget);
753+
748754
static unsigned getRegClassIDForLMUL(RISCVII::VLMUL LMul);
749755
static unsigned getSubregIndexByMVT(MVT VT, unsigned Index);
750756
static unsigned getRegClassIDForVecVT(MVT VT);

0 commit comments

Comments
 (0)