Skip to content

Commit 8603a7b

Browse files
committed
[RISCV] Add a query for exact VLEN to RISCVSubtarget [nfc]
We've now got enough of these in tree that we can see which patterns appear to be idiomatic. As such, extract a helper for checking if we know the exact VLEN.
1 parent 84ed55e commit 8603a7b

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,9 @@ void RISCVFrameLowering::adjustStackForRVV(MachineFunction &MF,
399399

400400
// Optimize compile time offset case
401401
StackOffset Offset = StackOffset::getScalable(Amount);
402-
if (STI.getRealMinVLen() == STI.getRealMaxVLen()) {
402+
if (auto VLEN = STI.getRealVLen()) {
403403
// 1. Multiply the number of v-slots by the (constant) length of register
404-
const int64_t VLENB = STI.getRealMinVLen() / 8;
404+
const int64_t VLENB = *VLEN / 8;
405405
assert(Amount % 8 == 0 &&
406406
"Reserve the stack by the multiple of one vector size.");
407407
const int64_t NumOfVReg = Amount / 8;

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,9 +577,8 @@ void RISCVDAGToDAGISel::selectVSETVLI(SDNode *Node) {
577577
SDValue VLOperand;
578578
unsigned Opcode = RISCV::PseudoVSETVLI;
579579
if (auto *C = dyn_cast<ConstantSDNode>(Node->getOperand(1))) {
580-
const unsigned VLEN = Subtarget->getRealMinVLen();
581-
if (VLEN == Subtarget->getRealMaxVLen())
582-
if (VLEN / RISCVVType::getSEWLMULRatio(SEW, VLMul) == C->getZExtValue())
580+
if (auto VLEN = Subtarget->getRealVLen())
581+
if (*VLEN / RISCVVType::getSEWLMULRatio(SEW, VLMul) == C->getZExtValue())
583582
VLMax = true;
584583
}
585584
if (VLMax || isAllOnesConstant(Node->getOperand(1))) {

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8092,12 +8092,11 @@ SDValue RISCVTargetLowering::lowerINSERT_VECTOR_ELT(SDValue Op,
80928092
// If we're compiling for an exact VLEN value, we can always perform
80938093
// the insert in m1 as we can determine the register corresponding to
80948094
// the index in the register group.
8095-
const unsigned MinVLen = Subtarget.getRealMinVLen();
8096-
const unsigned MaxVLen = Subtarget.getRealMaxVLen();
80978095
const MVT M1VT = getLMUL1VT(ContainerVT);
8098-
if (MinVLen == MaxVLen && ContainerVT.bitsGT(M1VT)) {
8096+
if (auto VLEN = Subtarget.getRealVLen();
8097+
VLEN && ContainerVT.bitsGT(M1VT)) {
80998098
EVT ElemVT = VecVT.getVectorElementType();
8100-
unsigned ElemsPerVReg = MinVLen / ElemVT.getFixedSizeInBits();
8099+
unsigned ElemsPerVReg = *VLEN / ElemVT.getFixedSizeInBits();
81018100
unsigned RemIdx = OrigIdx % ElemsPerVReg;
81028101
unsigned SubRegIdx = OrigIdx / ElemsPerVReg;
81038102
unsigned ExtractIdx =

llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ void RISCVRegisterInfo::lowerVSPILL(MachineBasicBlock::iterator II) const {
283283

284284
Register VL = MRI.createVirtualRegister(&RISCV::GPRRegClass);
285285
// Optimize for constant VLEN.
286-
if (STI.getRealMinVLen() == STI.getRealMaxVLen()) {
287-
const int64_t VLENB = STI.getRealMinVLen() / 8;
286+
if (auto VLEN = STI.getRealVLen()) {
287+
const int64_t VLENB = *VLEN / 8;
288288
int64_t Offset = VLENB * LMUL;
289289
STI.getInstrInfo()->movImm(MBB, II, DL, VL, Offset);
290290
} else {
@@ -360,8 +360,8 @@ void RISCVRegisterInfo::lowerVRELOAD(MachineBasicBlock::iterator II) const {
360360

361361
Register VL = MRI.createVirtualRegister(&RISCV::GPRRegClass);
362362
// Optimize for constant VLEN.
363-
if (STI.getRealMinVLen() == STI.getRealMaxVLen()) {
364-
const int64_t VLENB = STI.getRealMinVLen() / 8;
363+
if (auto VLEN = STI.getRealVLen()) {
364+
const int64_t VLENB = *VLEN / 8;
365365
int64_t Offset = VLENB * LMUL;
366366
STI.getInstrInfo()->movImm(MBB, II, DL, VL, Offset);
367367
} else {

llvm/lib/Target/RISCV/RISCVSubtarget.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
188188
unsigned VLen = getMaxRVVVectorSizeInBits();
189189
return VLen == 0 ? 65536 : VLen;
190190
}
191+
// If we know the exact VLEN, return it. Otherwise, return std::nullopt.
192+
std::optional<unsigned> getRealVLen() const {
193+
unsigned Min = getRealMinVLen();
194+
if (Min != getRealMaxVLen())
195+
return std::nullopt;
196+
return Min;
197+
}
198+
191199
RISCVABI::ABI getTargetABI() const { return TargetABI; }
192200
bool isSoftFPABI() const {
193201
return TargetABI == RISCVABI::ABI_LP64 ||

0 commit comments

Comments
 (0)