[llvm] faa43a8 - [RISCV] Rewrite isLegalElementTypeForRVV in terms of ValueTypes [nfc]
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Mon May 1 07:37:48 PDT 2023
Author: Philip Reames
Date: 2023-05-01T07:37:40-07:00
New Revision: faa43a80f70c639f40021a175c60857bdcf7cc1f
URL: https://github.com/llvm/llvm-project/commit/faa43a80f70c639f40021a175c60857bdcf7cc1f
DIFF: https://github.com/llvm/llvm-project/commit/faa43a80f70c639f40021a175c60857bdcf7cc1f.diff
LOG: [RISCV] Rewrite isLegalElementTypeForRVV in terms of ValueTypes [nfc]
This was briefly mentioned as a possibility in review discussion on D149369.
One slightly surprising bit to call out - these interfaces can get invoked with non-vector typed arguments. LoopVectorizer likes to call the costing interfaces with scalar types when unrolling, but not vectorizing. I found that surprising, not sure if others do.
Differential Revision: https://reviews.llvm.org/D149462
Added:
Modified:
llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.h
llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp b/llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp
index 590ea5ec7df43..e844e1b11271b 100644
--- a/llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp
@@ -445,11 +445,12 @@ bool RISCVGatherScatterLowering::tryCreateStridedLoadStore(IntrinsicInst *II,
Value *AlignOp) {
// Make sure the operation will be supported by the backend.
MaybeAlign MA = cast<ConstantInt>(AlignOp)->getMaybeAlignValue();
- if (!MA || !TLI->isLegalStridedLoadStore(*DL, DataType, *MA))
+ EVT DataTypeVT = TLI->getValueType(*DL, DataType);
+ if (!MA || !TLI->isLegalStridedLoadStore(DataTypeVT, *MA))
return false;
// FIXME: Let the backend type legalize by splitting/widening?
- if (!TLI->isTypeLegal(TLI->getValueType(*DL, DataType)))
+ if (!TLI->isTypeLegal(DataTypeVT))
return false;
// Pointer should be a GEP.
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 84dceb5862fc3..ff081a7eead9b 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -2060,27 +2060,30 @@ bool RISCVTargetLowering::mergeStoresAfterLegalization(EVT VT) const {
(VT.isFixedLengthVector() && VT.getVectorElementType() == MVT::i1);
}
-bool RISCVTargetLowering::isLegalElementTypeForRVV(Type *ScalarTy) const {
- if (ScalarTy->isPointerTy())
+bool RISCVTargetLowering::isLegalElementTypeForRVV(EVT ScalarTy) const {
+ if (!ScalarTy.isSimple())
+ return false;
+ switch (ScalarTy.getSimpleVT().SimpleTy) {
+ case MVT::iPTR:
return Subtarget.is64Bit() ? Subtarget.hasVInstructionsI64() : true;
-
- if (ScalarTy->isIntegerTy(8) || ScalarTy->isIntegerTy(16) ||
- ScalarTy->isIntegerTy(32))
+ case MVT::i8:
+ case MVT::i16:
+ case MVT::i32:
return true;
-
- if (ScalarTy->isIntegerTy(64))
+ case MVT::i64:
return Subtarget.hasVInstructionsI64();
-
- if (ScalarTy->isHalfTy())
+ case MVT::f16:
return Subtarget.hasVInstructionsF16();
- if (ScalarTy->isFloatTy())
+ case MVT::f32:
return Subtarget.hasVInstructionsF32();
- if (ScalarTy->isDoubleTy())
+ case MVT::f64:
return Subtarget.hasVInstructionsF64();
-
- return false;
+ default:
+ return false;
+ }
}
+
unsigned RISCVTargetLowering::combineRepeatedFPDivisors() const {
return NumRepeatedDivisors;
}
@@ -11458,8 +11461,7 @@ static SDValue performCONCAT_VECTORSCombine(SDNode *N, SelectionDAG &DAG,
return SDValue();
// Check that the operation is legal
- Type *WideVecTy = EVT(WideVecVT).getTypeForEVT(*DAG.getContext());
- if (!TLI.isLegalStridedLoadStore(DAG.getDataLayout(), WideVecTy, Align))
+ if (!TLI.isLegalStridedLoadStore(WideVecVT, Align))
return SDValue();
MVT ContainerVT = TLI.getContainerForFixedLengthVector(WideVecVT);
@@ -15815,12 +15817,14 @@ bool RISCVTargetLowering::isLegalInterleavedAccessType(
FixedVectorType *VTy, unsigned Factor, const DataLayout &DL) const {
if (!Subtarget.useRVVForFixedLengthVectors())
return false;
- if (!isLegalElementTypeForRVV(VTy->getElementType()))
- return false;
EVT VT = getValueType(DL, VTy);
// Don't lower vlseg/vsseg for fixed length vector types that can't be split.
if (!isTypeLegal(VT))
return false;
+
+ if (!isLegalElementTypeForRVV(VT.getScalarType()))
+ return false;
+
// Sometimes the interleaved access pass picks up splats as interleaves of one
// element. Don't lower these.
if (VTy->getNumElements() < 2)
@@ -15834,22 +15838,21 @@ bool RISCVTargetLowering::isLegalInterleavedAccessType(
return Factor * LMUL <= 8;
}
-bool RISCVTargetLowering::isLegalStridedLoadStore(const DataLayout &DL,
- Type *DataType,
+bool RISCVTargetLowering::isLegalStridedLoadStore(EVT DataType,
Align Alignment) const {
if (!Subtarget.hasVInstructions())
return false;
// Only support fixed vectors if we know the minimum vector size.
- if (isa<FixedVectorType>(DataType) && !Subtarget.useRVVForFixedLengthVectors())
+ if (DataType.isFixedLengthVector() && !Subtarget.useRVVForFixedLengthVectors())
return false;
- Type *ScalarType = DataType->getScalarType();
+ EVT ScalarType = DataType.getScalarType();
if (!isLegalElementTypeForRVV(ScalarType))
return false;
if (!Subtarget.enableUnalignedVectorMem() &&
- Alignment < DL.getTypeStoreSize(ScalarType).getFixedValue())
+ Alignment < ScalarType.getStoreSize())
return false;
return true;
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.h b/llvm/lib/Target/RISCV/RISCVISelLowering.h
index 849b11f5b0006..c020b27edf3e3 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.h
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.h
@@ -666,7 +666,7 @@ class RISCVTargetLowering : public TargetLowering {
bool shouldRemoveExtendFromGSIndex(EVT IndexVT, EVT DataVT) const override;
- bool isLegalElementTypeForRVV(Type *ScalarTy) const;
+ bool isLegalElementTypeForRVV(EVT ScalarTy) const;
bool shouldConvertFpToSat(unsigned Op, EVT FPVT, EVT VT) const override;
@@ -706,7 +706,7 @@ class RISCVTargetLowering : public TargetLowering {
/// Return true if a stride load store of the given result type and
/// alignment is legal.
- bool isLegalStridedLoadStore(const DataLayout &DL, Type *DataType, Align Alignment) const;
+ bool isLegalStridedLoadStore(EVT DataType, Align Alignment) const;
unsigned getMaxSupportedInterleaveFactor() const override { return 8; }
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
index 50d7c0a5631a1..5319bff98f700 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
@@ -179,23 +179,25 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
const Instruction *CxtI = nullptr);
bool isElementTypeLegalForScalableVector(Type *Ty) const {
- return TLI->isLegalElementTypeForRVV(Ty);
+ return TLI->isLegalElementTypeForRVV(TLI->getValueType(DL, Ty));
}
bool isLegalMaskedLoadStore(Type *DataType, Align Alignment) {
if (!ST->hasVInstructions())
return false;
+ EVT DataTypeVT = TLI->getValueType(DL, DataType);
+
// Only support fixed vectors if we know the minimum vector size.
- if (isa<FixedVectorType>(DataType) && !ST->useRVVForFixedLengthVectors())
+ if (DataTypeVT.isFixedLengthVector() && !ST->useRVVForFixedLengthVectors())
return false;
- auto *ElemType = DataType->getScalarType();
- if (!ST->enableUnalignedVectorMem() &&
- Alignment < DL.getTypeStoreSize(ElemType).getFixedValue())
+ EVT ElemType = DataTypeVT.getScalarType();
+ if (!ST->enableUnalignedVectorMem() && Alignment < ElemType.getStoreSize())
return false;
return TLI->isLegalElementTypeForRVV(ElemType);
+
}
bool isLegalMaskedLoad(Type *DataType, Align Alignment) {
@@ -209,13 +211,14 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
if (!ST->hasVInstructions())
return false;
+ EVT DataTypeVT = TLI->getValueType(DL, DataType);
+
// Only support fixed vectors if we know the minimum vector size.
- if (isa<FixedVectorType>(DataType) && !ST->useRVVForFixedLengthVectors())
+ if (DataTypeVT.isFixedLengthVector() && !ST->useRVVForFixedLengthVectors())
return false;
- auto *ElemType = DataType->getScalarType();
- if (!ST->enableUnalignedVectorMem() &&
- Alignment < DL.getTypeStoreSize(ElemType).getFixedValue())
+ EVT ElemType = DataTypeVT.getScalarType();
+ if (!ST->enableUnalignedVectorMem() && Alignment < ElemType.getStoreSize())
return false;
return TLI->isLegalElementTypeForRVV(ElemType);
@@ -262,7 +265,7 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
return true;
Type *Ty = RdxDesc.getRecurrenceType();
- if (!TLI->isLegalElementTypeForRVV(Ty))
+ if (!TLI->isLegalElementTypeForRVV(TLI->getValueType(DL, Ty)))
return false;
switch (RdxDesc.getRecurrenceKind()) {
More information about the llvm-commits
mailing list