Skip to content

Commit

Permalink
[RISCV] Add a query for exact VLEN to RISCVSubtarget [nfc]
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
preames committed Feb 21, 2024
1 parent 84ed55e commit 8603a7b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ void RISCVFrameLowering::adjustStackForRVV(MachineFunction &MF,

// Optimize compile time offset case
StackOffset Offset = StackOffset::getScalable(Amount);
if (STI.getRealMinVLen() == STI.getRealMaxVLen()) {
if (auto VLEN = STI.getRealVLen()) {
// 1. Multiply the number of v-slots by the (constant) length of register
const int64_t VLENB = STI.getRealMinVLen() / 8;
const int64_t VLENB = *VLEN / 8;
assert(Amount % 8 == 0 &&
"Reserve the stack by the multiple of one vector size.");
const int64_t NumOfVReg = Amount / 8;
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,8 @@ void RISCVDAGToDAGISel::selectVSETVLI(SDNode *Node) {
SDValue VLOperand;
unsigned Opcode = RISCV::PseudoVSETVLI;
if (auto *C = dyn_cast<ConstantSDNode>(Node->getOperand(1))) {
const unsigned VLEN = Subtarget->getRealMinVLen();
if (VLEN == Subtarget->getRealMaxVLen())
if (VLEN / RISCVVType::getSEWLMULRatio(SEW, VLMul) == C->getZExtValue())
if (auto VLEN = Subtarget->getRealVLen())
if (*VLEN / RISCVVType::getSEWLMULRatio(SEW, VLMul) == C->getZExtValue())
VLMax = true;
}
if (VLMax || isAllOnesConstant(Node->getOperand(1))) {
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8092,12 +8092,11 @@ SDValue RISCVTargetLowering::lowerINSERT_VECTOR_ELT(SDValue Op,
// If we're compiling for an exact VLEN value, we can always perform
// the insert in m1 as we can determine the register corresponding to
// the index in the register group.
const unsigned MinVLen = Subtarget.getRealMinVLen();
const unsigned MaxVLen = Subtarget.getRealMaxVLen();
const MVT M1VT = getLMUL1VT(ContainerVT);
if (MinVLen == MaxVLen && ContainerVT.bitsGT(M1VT)) {
if (auto VLEN = Subtarget.getRealVLen();
VLEN && ContainerVT.bitsGT(M1VT)) {
EVT ElemVT = VecVT.getVectorElementType();
unsigned ElemsPerVReg = MinVLen / ElemVT.getFixedSizeInBits();
unsigned ElemsPerVReg = *VLEN / ElemVT.getFixedSizeInBits();
unsigned RemIdx = OrigIdx % ElemsPerVReg;
unsigned SubRegIdx = OrigIdx / ElemsPerVReg;
unsigned ExtractIdx =
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ void RISCVRegisterInfo::lowerVSPILL(MachineBasicBlock::iterator II) const {

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

Register VL = MRI.createVirtualRegister(&RISCV::GPRRegClass);
// Optimize for constant VLEN.
if (STI.getRealMinVLen() == STI.getRealMaxVLen()) {
const int64_t VLENB = STI.getRealMinVLen() / 8;
if (auto VLEN = STI.getRealVLen()) {
const int64_t VLENB = *VLEN / 8;
int64_t Offset = VLENB * LMUL;
STI.getInstrInfo()->movImm(MBB, II, DL, VL, Offset);
} else {
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/Target/RISCV/RISCVSubtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
unsigned VLen = getMaxRVVVectorSizeInBits();
return VLen == 0 ? 65536 : VLen;
}
// If we know the exact VLEN, return it. Otherwise, return std::nullopt.
std::optional<unsigned> getRealVLen() const {
unsigned Min = getRealMinVLen();
if (Min != getRealMaxVLen())
return std::nullopt;
return Min;
}

RISCVABI::ABI getTargetABI() const { return TargetABI; }
bool isSoftFPABI() const {
return TargetABI == RISCVABI::ABI_LP64 ||
Expand Down

0 comments on commit 8603a7b

Please sign in to comment.