[llvm] 8603a7b - [RISCV] Add a query for exact VLEN to RISCVSubtarget [nfc]
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 20 17:27:58 PST 2024
Author: Philip Reames
Date: 2024-02-20T17:27:47-08:00
New Revision: 8603a7b21f301508d3a6af9f2238c7b92ce19617
URL: https://github.com/llvm/llvm-project/commit/8603a7b21f301508d3a6af9f2238c7b92ce19617
DIFF: https://github.com/llvm/llvm-project/commit/8603a7b21f301508d3a6af9f2238c7b92ce19617.diff
LOG: [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.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
llvm/lib/Target/RISCV/RISCVSubtarget.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 7e3dcb3283caba..8bac41372b5a83 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -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;
diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
index 80797e36ad40fe..904f1d7fdf9065 100644
--- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
@@ -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))) {
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 9ab6895aed521e..874c851cd9147a 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -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 =
diff --git a/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp b/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
index ca519dbc4c0359..9d1f01dffaaf47 100644
--- a/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp
@@ -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 {
@@ -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 {
diff --git a/llvm/lib/Target/RISCV/RISCVSubtarget.h b/llvm/lib/Target/RISCV/RISCVSubtarget.h
index 8c55efa69a6a5f..4b60d7aff22a0f 100644
--- a/llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ b/llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -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 ||
More information about the llvm-commits
mailing list