Convert cost table lookup functions to return a pointer to the entry or nullptr instead of the index.

This avoid mentioning the table name an extra time and allows the lookup to be done directly in the ifs by relying on the bool conversion of the pointer.

While there make use of ArrayRef and std::find_if.

llvm-svn: 251382
This commit is contained in:
Craig Topper 2015-10-27 04:14:24 +00:00
parent 69798fb5ec
commit ee0c859788
4 changed files with 142 additions and 168 deletions

View File

@ -15,6 +15,8 @@
#ifndef LLVM_TARGET_COSTTABLE_H_ #ifndef LLVM_TARGET_COSTTABLE_H_
#define LLVM_TARGET_COSTTABLE_H_ #define LLVM_TARGET_COSTTABLE_H_
#include "llvm/ADT/ArrayRef.h"
namespace llvm { namespace llvm {
/// Cost Table Entry /// Cost Table Entry
@ -27,21 +29,23 @@ struct CostTblEntry {
/// Find in cost table, TypeTy must be comparable to CompareTy by == /// Find in cost table, TypeTy must be comparable to CompareTy by ==
template <class TypeTy, class CompareTy> template <class TypeTy, class CompareTy>
int CostTableLookup(const CostTblEntry<TypeTy> *Tbl, unsigned len, int ISD, const CostTblEntry<TypeTy> *CostTableLookup(ArrayRef<CostTblEntry<TypeTy>> Tbl,
CompareTy Ty) { int ISD, CompareTy Ty) {
for (unsigned int i = 0; i < len; ++i) auto I = std::find_if(Tbl.begin(), Tbl.end(),
if (ISD == Tbl[i].ISD && Ty == Tbl[i].Type) [=](const CostTblEntry<TypeTy> &Entry) {
return i; return ISD == Entry.ISD && Ty == Entry.Type; });
if (I != Tbl.end())
return I;
// Could not find an entry. // Could not find an entry.
return -1; return nullptr;
} }
/// Find in cost table, TypeTy must be comparable to CompareTy by == /// Find in cost table, TypeTy must be comparable to CompareTy by ==
template <class TypeTy, class CompareTy, unsigned N> template <class TypeTy, class CompareTy, unsigned N>
int CostTableLookup(const CostTblEntry<TypeTy>(&Tbl)[N], int ISD, const CostTblEntry<TypeTy> *CostTableLookup(const CostTblEntry<TypeTy>(&Tbl)[N],
CompareTy Ty) { int ISD, CompareTy Ty) {
return CostTableLookup(Tbl, N, ISD, Ty); return CostTableLookup(makeArrayRef(Tbl), ISD, Ty);
} }
/// Type Conversion Cost Table /// Type Conversion Cost Table
@ -56,23 +60,28 @@ struct TypeConversionCostTblEntry {
/// Find in type conversion cost table, TypeTy must be comparable to CompareTy /// Find in type conversion cost table, TypeTy must be comparable to CompareTy
/// by == /// by ==
template <class TypeTy, class CompareTy> template <class TypeTy, class CompareTy>
int ConvertCostTableLookup(const TypeConversionCostTblEntry<TypeTy> *Tbl, const TypeConversionCostTblEntry<TypeTy> *
unsigned len, int ISD, CompareTy Dst, ConvertCostTableLookup(ArrayRef<TypeConversionCostTblEntry<TypeTy>> Tbl,
CompareTy Src) { int ISD, CompareTy Dst, CompareTy Src) {
for (unsigned int i = 0; i < len; ++i) auto I = std::find_if(Tbl.begin(), Tbl.end(),
if (ISD == Tbl[i].ISD && Src == Tbl[i].Src && Dst == Tbl[i].Dst) [=](const TypeConversionCostTblEntry<TypeTy> &Entry) {
return i; return ISD == Entry.ISD && Src == Entry.Src &&
Dst == Entry.Dst;
});
if (I != Tbl.end())
return I;
// Could not find an entry. // Could not find an entry.
return -1; return nullptr;
} }
/// Find in type conversion cost table, TypeTy must be comparable to CompareTy /// Find in type conversion cost table, TypeTy must be comparable to CompareTy
/// by == /// by ==
template <class TypeTy, class CompareTy, unsigned N> template <class TypeTy, class CompareTy, unsigned N>
int ConvertCostTableLookup(const TypeConversionCostTblEntry<TypeTy>(&Tbl)[N], const TypeConversionCostTblEntry<TypeTy> *
ConvertCostTableLookup(const TypeConversionCostTblEntry<TypeTy>(&Tbl)[N],
int ISD, CompareTy Dst, CompareTy Src) { int ISD, CompareTy Dst, CompareTy Src) {
return ConvertCostTableLookup(Tbl, N, ISD, Dst, Src); return ConvertCostTableLookup(makeArrayRef(Tbl), ISD, Dst, Src);
} }
} // namespace llvm } // namespace llvm

View File

@ -282,10 +282,10 @@ int AArch64TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) {
{ ISD::FP_TO_UINT, MVT::v2i8, MVT::v2f64, 2 }, { ISD::FP_TO_UINT, MVT::v2i8, MVT::v2f64, 2 },
}; };
int Idx = ConvertCostTableLookup(ConversionTbl, ISD, DstTy.getSimpleVT(), if (const auto *Entry = ConvertCostTableLookup(ConversionTbl, ISD,
SrcTy.getSimpleVT()); DstTy.getSimpleVT(),
if (Idx != -1) SrcTy.getSimpleVT()))
return ConversionTbl[Idx].Cost; return Entry->Cost;
return BaseT::getCastInstrCost(Opcode, Dst, Src); return BaseT::getCastInstrCost(Opcode, Dst, Src);
} }
@ -398,11 +398,10 @@ int AArch64TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
EVT SelCondTy = TLI->getValueType(DL, CondTy); EVT SelCondTy = TLI->getValueType(DL, CondTy);
EVT SelValTy = TLI->getValueType(DL, ValTy); EVT SelValTy = TLI->getValueType(DL, ValTy);
if (SelCondTy.isSimple() && SelValTy.isSimple()) { if (SelCondTy.isSimple() && SelValTy.isSimple()) {
int Idx = if (const auto *Entry = ConvertCostTableLookup(VectorSelectTbl, ISD,
ConvertCostTableLookup(VectorSelectTbl, ISD, SelCondTy.getSimpleVT(), SelCondTy.getSimpleVT(),
SelValTy.getSimpleVT()); SelValTy.getSimpleVT()))
if (Idx != -1) return Entry->Cost;
return VectorSelectTbl[Idx].Cost;
} }
} }
return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy); return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy);

View File

@ -62,9 +62,8 @@ int ARMTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) {
if (Src->isVectorTy() && ST->hasNEON() && (ISD == ISD::FP_ROUND || if (Src->isVectorTy() && ST->hasNEON() && (ISD == ISD::FP_ROUND ||
ISD == ISD::FP_EXTEND)) { ISD == ISD::FP_EXTEND)) {
std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Src); std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Src);
int Idx = CostTableLookup(NEONFltDblTbl, ISD, LT.second); if (const auto *Entry = CostTableLookup(NEONFltDblTbl, ISD, LT.second))
if (Idx != -1) return LT.first * Entry->Cost;
return LT.first * NEONFltDblTbl[Idx].Cost;
} }
EVT SrcTy = TLI->getValueType(DL, Src); EVT SrcTy = TLI->getValueType(DL, Src);
@ -153,10 +152,10 @@ int ARMTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) {
}; };
if (SrcTy.isVector() && ST->hasNEON()) { if (SrcTy.isVector() && ST->hasNEON()) {
int Idx = ConvertCostTableLookup(NEONVectorConversionTbl, ISD, if (const auto *Entry = ConvertCostTableLookup(NEONVectorConversionTbl, ISD,
DstTy.getSimpleVT(), SrcTy.getSimpleVT()); DstTy.getSimpleVT(),
if (Idx != -1) SrcTy.getSimpleVT()))
return NEONVectorConversionTbl[Idx].Cost; return Entry->Cost;
} }
// Scalar float to integer conversions. // Scalar float to integer conversions.
@ -184,10 +183,10 @@ int ARMTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) {
{ ISD::FP_TO_UINT, MVT::i64, MVT::f64, 10 } { ISD::FP_TO_UINT, MVT::i64, MVT::f64, 10 }
}; };
if (SrcTy.isFloatingPoint() && ST->hasNEON()) { if (SrcTy.isFloatingPoint() && ST->hasNEON()) {
int Idx = ConvertCostTableLookup(NEONFloatConversionTbl, ISD, if (const auto *Entry = ConvertCostTableLookup(NEONFloatConversionTbl, ISD,
DstTy.getSimpleVT(), SrcTy.getSimpleVT()); DstTy.getSimpleVT(),
if (Idx != -1) SrcTy.getSimpleVT()))
return NEONFloatConversionTbl[Idx].Cost; return Entry->Cost;
} }
// Scalar integer to float conversions. // Scalar integer to float conversions.
@ -216,10 +215,10 @@ int ARMTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) {
}; };
if (SrcTy.isInteger() && ST->hasNEON()) { if (SrcTy.isInteger() && ST->hasNEON()) {
int Idx = ConvertCostTableLookup(NEONIntegerConversionTbl, ISD, if (const auto *Entry = ConvertCostTableLookup(NEONIntegerConversionTbl,
DstTy.getSimpleVT(), SrcTy.getSimpleVT()); ISD, DstTy.getSimpleVT(),
if (Idx != -1) SrcTy.getSimpleVT()))
return NEONIntegerConversionTbl[Idx].Cost; return Entry->Cost;
} }
// Scalar integer conversion costs. // Scalar integer conversion costs.
@ -236,10 +235,10 @@ int ARMTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) {
}; };
if (SrcTy.isInteger()) { if (SrcTy.isInteger()) {
int Idx = ConvertCostTableLookup(ARMIntegerConversionTbl, ISD, if (const auto *Entry = ConvertCostTableLookup(ARMIntegerConversionTbl, ISD,
DstTy.getSimpleVT(), SrcTy.getSimpleVT()); DstTy.getSimpleVT(),
if (Idx != -1) SrcTy.getSimpleVT()))
return ARMIntegerConversionTbl[Idx].Cost; return Entry->Cost;
} }
return BaseT::getCastInstrCost(Opcode, Dst, Src); return BaseT::getCastInstrCost(Opcode, Dst, Src);
@ -291,11 +290,10 @@ int ARMTTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy) {
EVT SelCondTy = TLI->getValueType(DL, CondTy); EVT SelCondTy = TLI->getValueType(DL, CondTy);
EVT SelValTy = TLI->getValueType(DL, ValTy); EVT SelValTy = TLI->getValueType(DL, ValTy);
if (SelCondTy.isSimple() && SelValTy.isSimple()) { if (SelCondTy.isSimple() && SelValTy.isSimple()) {
int Idx = ConvertCostTableLookup(NEONVectorSelectTbl, ISD, if (const auto *Entry = ConvertCostTableLookup(NEONVectorSelectTbl, ISD,
SelCondTy.getSimpleVT(), SelCondTy.getSimpleVT(),
SelValTy.getSimpleVT()); SelValTy.getSimpleVT()))
if (Idx != -1) return Entry->Cost;
return NEONVectorSelectTbl[Idx].Cost;
} }
std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, ValTy); std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, ValTy);
@ -361,11 +359,11 @@ int ARMTTIImpl::getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index,
std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Tp); std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Tp);
int Idx = CostTableLookup(NEONShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second); if (const auto *Entry = CostTableLookup(NEONShuffleTbl, ISD::VECTOR_SHUFFLE,
if (Idx == -1) LT.second))
return BaseT::getShuffleCost(Kind, Tp, Index, SubTp); return LT.first * Entry->Cost;
return LT.first * NEONShuffleTbl[Idx].Cost; return BaseT::getShuffleCost(Kind, Tp, Index, SubTp);
} }
if (Kind == TTI::SK_Alternate) { if (Kind == TTI::SK_Alternate) {
static const CostTblEntry<MVT::SimpleValueType> NEONAltShuffleTbl[] = { static const CostTblEntry<MVT::SimpleValueType> NEONAltShuffleTbl[] = {
@ -386,11 +384,10 @@ int ARMTTIImpl::getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index,
{ISD::VECTOR_SHUFFLE, MVT::v16i8, 32}}; {ISD::VECTOR_SHUFFLE, MVT::v16i8, 32}};
std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Tp); std::pair<int, MVT> LT = TLI->getTypeLegalizationCost(DL, Tp);
int Idx = if (const auto *Entry = CostTableLookup(NEONAltShuffleTbl,
CostTableLookup(NEONAltShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second); ISD::VECTOR_SHUFFLE, LT.second))
if (Idx == -1) return LT.first * Entry->Cost;
return BaseT::getShuffleCost(Kind, Tp, Index, SubTp); return BaseT::getShuffleCost(Kind, Tp, Index, SubTp);
return LT.first * NEONAltShuffleTbl[Idx].Cost;
} }
return BaseT::getShuffleCost(Kind, Tp, Index, SubTp); return BaseT::getShuffleCost(Kind, Tp, Index, SubTp);
} }
@ -446,13 +443,9 @@ int ARMTTIImpl::getArithmeticInstrCost(
// Multiplication. // Multiplication.
}; };
int Idx = -1;
if (ST->hasNEON()) if (ST->hasNEON())
Idx = CostTableLookup(CostTbl, ISDOpcode, LT.second); if (const auto *Entry = CostTableLookup(CostTbl, ISDOpcode, LT.second))
return LT.first * Entry->Cost;
if (Idx != -1)
return LT.first * CostTbl[Idx].Cost;
int Cost = BaseT::getArithmeticInstrCost(Opcode, Ty, Op1Info, Op2Info, int Cost = BaseT::getArithmeticInstrCost(Opcode, Ty, Op1Info, Op2Info,
Opd1PropInfo, Opd2PropInfo); Opd1PropInfo, Opd2PropInfo);

View File

@ -127,9 +127,9 @@ int X86TTIImpl::getArithmeticInstrCost(
if (Op2Info == TargetTransformInfo::OK_UniformConstantValue && if (Op2Info == TargetTransformInfo::OK_UniformConstantValue &&
ST->hasAVX2()) { ST->hasAVX2()) {
int Idx = CostTableLookup(AVX2UniformConstCostTable, ISD, LT.second); if (const auto *Entry = CostTableLookup(AVX2UniformConstCostTable, ISD,
if (Idx != -1) LT.second))
return LT.first * AVX2UniformConstCostTable[Idx].Cost; return LT.first * Entry->Cost;
} }
static const CostTblEntry<MVT::SimpleValueType> AVX512CostTable[] = { static const CostTblEntry<MVT::SimpleValueType> AVX512CostTable[] = {
@ -142,9 +142,8 @@ int X86TTIImpl::getArithmeticInstrCost(
}; };
if (ST->hasAVX512()) { if (ST->hasAVX512()) {
int Idx = CostTableLookup(AVX512CostTable, ISD, LT.second); if (const auto *Entry = CostTableLookup(AVX512CostTable, ISD, LT.second))
if (Idx != -1) return LT.first * Entry->Cost;
return LT.first * AVX512CostTable[Idx].Cost;
} }
static const CostTblEntry<MVT::SimpleValueType> AVX2CostTable[] = { static const CostTblEntry<MVT::SimpleValueType> AVX2CostTable[] = {
@ -171,9 +170,8 @@ int X86TTIImpl::getArithmeticInstrCost(
// is lowered into a vector multiply (vpmullw). // is lowered into a vector multiply (vpmullw).
return LT.first; return LT.first;
int Idx = CostTableLookup(AVX2CostTable, ISD, LT.second); if (const auto *Entry = CostTableLookup(AVX2CostTable, ISD, LT.second))
if (Idx != -1) return LT.first * Entry->Cost;
return LT.first * AVX2CostTable[Idx].Cost;
} }
static const CostTblEntry<MVT::SimpleValueType> XOPCostTable[] = { static const CostTblEntry<MVT::SimpleValueType> XOPCostTable[] = {
@ -207,9 +205,8 @@ int X86TTIImpl::getArithmeticInstrCost(
// Look for XOP lowering tricks. // Look for XOP lowering tricks.
if (ST->hasXOP()) { if (ST->hasXOP()) {
int Idx = CostTableLookup(XOPCostTable, ISD, LT.second); if (const auto *Entry = CostTableLookup(XOPCostTable, ISD, LT.second))
if (Idx != -1) return LT.first * Entry->Cost;
return LT.first * XOPCostTable[Idx].Cost;
} }
static const CostTblEntry<MVT::SimpleValueType> AVX2CustomCostTable[] = { static const CostTblEntry<MVT::SimpleValueType> AVX2CustomCostTable[] = {
@ -237,9 +234,9 @@ int X86TTIImpl::getArithmeticInstrCost(
// Look for AVX2 lowering tricks for custom cases. // Look for AVX2 lowering tricks for custom cases.
if (ST->hasAVX2()) { if (ST->hasAVX2()) {
int Idx = CostTableLookup(AVX2CustomCostTable, ISD, LT.second); if (const auto *Entry = CostTableLookup(AVX2CustomCostTable, ISD,
if (Idx != -1) LT.second))
return LT.first * AVX2CustomCostTable[Idx].Cost; return LT.first * Entry->Cost;
} }
static const CostTblEntry<MVT::SimpleValueType> static const CostTblEntry<MVT::SimpleValueType>
@ -286,9 +283,9 @@ int X86TTIImpl::getArithmeticInstrCost(
if (ISD == ISD::SDIV && LT.second == MVT::v4i32 && ST->hasSSE41()) if (ISD == ISD::SDIV && LT.second == MVT::v4i32 && ST->hasSSE41())
return LT.first * 15; return LT.first * 15;
int Idx = CostTableLookup(SSE2UniformConstCostTable, ISD, LT.second); if (const auto *Entry = CostTableLookup(SSE2UniformConstCostTable, ISD,
if (Idx != -1) LT.second))
return LT.first * SSE2UniformConstCostTable[Idx].Cost; return LT.first * Entry->Cost;
} }
if (ISD == ISD::SHL && if (ISD == ISD::SHL &&
@ -366,9 +363,8 @@ int X86TTIImpl::getArithmeticInstrCost(
}; };
if (ST->hasSSE2()) { if (ST->hasSSE2()) {
int Idx = CostTableLookup(SSE2CostTable, ISD, LT.second); if (const auto *Entry = CostTableLookup(SSE2CostTable, ISD, LT.second))
if (Idx != -1) return LT.first * Entry->Cost;
return LT.first * SSE2CostTable[Idx].Cost;
} }
static const CostTblEntry<MVT::SimpleValueType> AVX1CostTable[] = { static const CostTblEntry<MVT::SimpleValueType> AVX1CostTable[] = {
@ -393,9 +389,8 @@ int X86TTIImpl::getArithmeticInstrCost(
if (ST->hasAVX() && !ST->hasAVX2()) { if (ST->hasAVX() && !ST->hasAVX2()) {
MVT VT = LT.second; MVT VT = LT.second;
int Idx = CostTableLookup(AVX1CostTable, ISD, VT); if (const auto *Entry = CostTableLookup(AVX1CostTable, ISD, VT))
if (Idx != -1) return LT.first * Entry->Cost;
return LT.first * AVX1CostTable[Idx].Cost;
} }
// Custom lowering of vectors. // Custom lowering of vectors.
@ -405,9 +400,8 @@ int X86TTIImpl::getArithmeticInstrCost(
{ ISD::MUL, MVT::v2i64, 9 }, { ISD::MUL, MVT::v2i64, 9 },
{ ISD::MUL, MVT::v4i64, 9 }, { ISD::MUL, MVT::v4i64, 9 },
}; };
int Idx = CostTableLookup(CustomLowered, ISD, LT.second); if (const auto *Entry = CostTableLookup(CustomLowered, ISD, LT.second))
if (Idx != -1) return LT.first * Entry->Cost;
return LT.first * CustomLowered[Idx].Cost;
// Special lowering of v4i32 mul on sse2, sse3: Lower v4i32 mul as 2x shuffle, // Special lowering of v4i32 mul on sse2, sse3: Lower v4i32 mul as 2x shuffle,
// 2x pmuludq, 2x shuffle. // 2x pmuludq, 2x shuffle.
@ -461,11 +455,10 @@ int X86TTIImpl::getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index,
{ISD::VECTOR_SHUFFLE, MVT::v32i8, 9} {ISD::VECTOR_SHUFFLE, MVT::v32i8, 9}
}; };
if (ST->hasAVX()) { if (ST->hasAVX())
int Idx = CostTableLookup(AVXAltShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second); if (const auto *Entry = CostTableLookup(AVXAltShuffleTbl,
if (Idx != -1) ISD::VECTOR_SHUFFLE, LT.second))
return LT.first * AVXAltShuffleTbl[Idx].Cost; return LT.first * Entry->Cost;
}
static const CostTblEntry<MVT::SimpleValueType> SSE41AltShuffleTbl[] = { static const CostTblEntry<MVT::SimpleValueType> SSE41AltShuffleTbl[] = {
// These are lowered into movsd. // These are lowered into movsd.
@ -485,11 +478,10 @@ int X86TTIImpl::getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index,
{ISD::VECTOR_SHUFFLE, MVT::v16i8, 3} {ISD::VECTOR_SHUFFLE, MVT::v16i8, 3}
}; };
if (ST->hasSSE41()) { if (ST->hasSSE41())
int Idx = CostTableLookup(SSE41AltShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second); if (const auto *Entry = CostTableLookup(SSE41AltShuffleTbl, ISD::VECTOR_SHUFFLE,
if (Idx != -1) LT.second))
return LT.first * SSE41AltShuffleTbl[Idx].Cost; return LT.first * Entry->Cost;
}
static const CostTblEntry<MVT::SimpleValueType> SSSE3AltShuffleTbl[] = { static const CostTblEntry<MVT::SimpleValueType> SSSE3AltShuffleTbl[] = {
{ISD::VECTOR_SHUFFLE, MVT::v2i64, 1}, // movsd {ISD::VECTOR_SHUFFLE, MVT::v2i64, 1}, // movsd
@ -504,11 +496,10 @@ int X86TTIImpl::getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index,
{ISD::VECTOR_SHUFFLE, MVT::v16i8, 3} // pshufb + pshufb + or {ISD::VECTOR_SHUFFLE, MVT::v16i8, 3} // pshufb + pshufb + or
}; };
if (ST->hasSSSE3()) { if (ST->hasSSSE3())
int Idx = CostTableLookup(SSSE3AltShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second); if (const auto *Entry = CostTableLookup(SSSE3AltShuffleTbl,
if (Idx != -1) ISD::VECTOR_SHUFFLE, LT.second))
return LT.first * SSSE3AltShuffleTbl[Idx].Cost; return LT.first * Entry->Cost;
}
static const CostTblEntry<MVT::SimpleValueType> SSEAltShuffleTbl[] = { static const CostTblEntry<MVT::SimpleValueType> SSEAltShuffleTbl[] = {
{ISD::VECTOR_SHUFFLE, MVT::v2i64, 1}, // movsd {ISD::VECTOR_SHUFFLE, MVT::v2i64, 1}, // movsd
@ -525,9 +516,9 @@ int X86TTIImpl::getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index,
}; };
// Fall-back (SSE3 and SSE2). // Fall-back (SSE3 and SSE2).
int Idx = CostTableLookup(SSEAltShuffleTbl, ISD::VECTOR_SHUFFLE, LT.second); if (const auto *Entry = CostTableLookup(SSEAltShuffleTbl,
if (Idx != -1) ISD::VECTOR_SHUFFLE, LT.second))
return LT.first * SSEAltShuffleTbl[Idx].Cost; return LT.first * Entry->Cost;
return BaseT::getShuffleCost(Kind, Tp, Index, SubTp); return BaseT::getShuffleCost(Kind, Tp, Index, SubTp);
} }
@ -702,17 +693,15 @@ int X86TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) {
std::pair<int, MVT> LTDest = TLI->getTypeLegalizationCost(DL, Dst); std::pair<int, MVT> LTDest = TLI->getTypeLegalizationCost(DL, Dst);
if (ST->hasSSE2() && !ST->hasAVX()) { if (ST->hasSSE2() && !ST->hasAVX()) {
int Idx = if (const auto *Entry = ConvertCostTableLookup(SSE2ConvTbl, ISD,
ConvertCostTableLookup(SSE2ConvTbl, ISD, LTDest.second, LTSrc.second); LTDest.second, LTSrc.second))
if (Idx != -1) return LTSrc.first * Entry->Cost;
return LTSrc.first * SSE2ConvTbl[Idx].Cost;
} }
if (ST->hasAVX512()) { if (ST->hasAVX512()) {
int Idx = ConvertCostTableLookup(AVX512ConversionTbl, ISD, LTDest.second, if (const auto *Entry = ConvertCostTableLookup(AVX512ConversionTbl, ISD,
LTSrc.second); LTDest.second, LTSrc.second))
if (Idx != -1) return Entry->Cost;
return AVX512ConversionTbl[Idx].Cost;
} }
EVT SrcTy = TLI->getValueType(DL, Src); EVT SrcTy = TLI->getValueType(DL, Src);
@ -723,17 +712,17 @@ int X86TTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) {
return BaseT::getCastInstrCost(Opcode, Dst, Src); return BaseT::getCastInstrCost(Opcode, Dst, Src);
if (ST->hasAVX2()) { if (ST->hasAVX2()) {
int Idx = ConvertCostTableLookup(AVX2ConversionTbl, ISD, if (const auto *Entry = ConvertCostTableLookup(AVX2ConversionTbl, ISD,
DstTy.getSimpleVT(), SrcTy.getSimpleVT()); DstTy.getSimpleVT(),
if (Idx != -1) SrcTy.getSimpleVT()))
return AVX2ConversionTbl[Idx].Cost; return Entry->Cost;
} }
if (ST->hasAVX()) { if (ST->hasAVX()) {
int Idx = ConvertCostTableLookup(AVXConversionTbl, ISD, DstTy.getSimpleVT(), if (const auto *Entry = ConvertCostTableLookup(AVXConversionTbl, ISD,
SrcTy.getSimpleVT()); DstTy.getSimpleVT(),
if (Idx != -1) SrcTy.getSimpleVT()))
return AVXConversionTbl[Idx].Cost; return Entry->Cost;
} }
return BaseT::getCastInstrCost(Opcode, Dst, Src); return BaseT::getCastInstrCost(Opcode, Dst, Src);
@ -781,29 +770,21 @@ int X86TTIImpl::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy) {
{ ISD::SETCC, MVT::v16f32, 1 }, { ISD::SETCC, MVT::v16f32, 1 },
}; };
if (ST->hasAVX512()) { if (ST->hasAVX512())
int Idx = CostTableLookup(AVX512CostTbl, ISD, MTy); if (const auto *Entry = CostTableLookup(AVX512CostTbl, ISD, MTy))
if (Idx != -1) return LT.first * Entry->Cost;
return LT.first * AVX512CostTbl[Idx].Cost;
}
if (ST->hasAVX2()) { if (ST->hasAVX2())
int Idx = CostTableLookup(AVX2CostTbl, ISD, MTy); if (const auto *Entry = CostTableLookup(AVX2CostTbl, ISD, MTy))
if (Idx != -1) return LT.first * Entry->Cost;
return LT.first * AVX2CostTbl[Idx].Cost;
}
if (ST->hasAVX()) { if (ST->hasAVX())
int Idx = CostTableLookup(AVX1CostTbl, ISD, MTy); if (const auto *Entry = CostTableLookup(AVX1CostTbl, ISD, MTy))
if (Idx != -1) return LT.first * Entry->Cost;
return LT.first * AVX1CostTbl[Idx].Cost;
}
if (ST->hasSSE42()) { if (ST->hasSSE42())
int Idx = CostTableLookup(SSE42CostTbl, ISD, MTy); if (const auto *Entry = CostTableLookup(SSE42CostTbl, ISD, MTy))
if (Idx != -1) return LT.first * Entry->Cost;
return LT.first * SSE42CostTbl[Idx].Cost;
}
return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy); return BaseT::getCmpSelInstrCost(Opcode, ValTy, CondTy);
} }
@ -1004,29 +985,21 @@ int X86TTIImpl::getReductionCost(unsigned Opcode, Type *ValTy,
}; };
if (IsPairwise) { if (IsPairwise) {
if (ST->hasAVX()) { if (ST->hasAVX())
int Idx = CostTableLookup(AVX1CostTblPairWise, ISD, MTy); if (const auto *Entry = CostTableLookup(AVX1CostTblPairWise, ISD, MTy))
if (Idx != -1) return LT.first * Entry->Cost;
return LT.first * AVX1CostTblPairWise[Idx].Cost;
}
if (ST->hasSSE42()) { if (ST->hasSSE42())
int Idx = CostTableLookup(SSE42CostTblPairWise, ISD, MTy); if (const auto *Entry = CostTableLookup(SSE42CostTblPairWise, ISD, MTy))
if (Idx != -1) return LT.first * Entry->Cost;
return LT.first * SSE42CostTblPairWise[Idx].Cost;
}
} else { } else {
if (ST->hasAVX()) { if (ST->hasAVX())
int Idx = CostTableLookup(AVX1CostTblNoPairWise, ISD, MTy); if (const auto *Entry = CostTableLookup(AVX1CostTblNoPairWise, ISD, MTy))
if (Idx != -1) return LT.first * Entry->Cost;
return LT.first * AVX1CostTblNoPairWise[Idx].Cost;
}
if (ST->hasSSE42()) { if (ST->hasSSE42())
int Idx = CostTableLookup(SSE42CostTblNoPairWise, ISD, MTy); if (const auto *Entry = CostTableLookup(SSE42CostTblNoPairWise, ISD, MTy))
if (Idx != -1) return LT.first * Entry->Cost;
return LT.first * SSE42CostTblNoPairWise[Idx].Cost;
}
} }
return BaseT::getReductionCost(Opcode, ValTy, IsPairwise); return BaseT::getReductionCost(Opcode, ValTy, IsPairwise);