1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 03:23:01 +02:00

CostModel: Add tables for the common x86 compares.

llvm-svn: 167421
This commit is contained in:
Nadav Rotem 2012-11-05 23:48:20 +00:00
parent 8ddfd47801
commit 890d7c7f8e
3 changed files with 125 additions and 8 deletions

View File

@ -17517,6 +17517,15 @@ struct X86CostTblEntry {
unsigned Cost;
};
int FindInTable(const X86CostTblEntry *Tbl, unsigned len, int ISD, MVT Ty) {
for (unsigned int i = 0; i < len; ++i)
if (Tbl[i].ISD == ISD && Tbl[i].Type == Ty)
return i;
// Could not find an entry.
return -1;
}
unsigned
X86VectorTargetTransformInfo::getArithmeticInstrCost(unsigned Opcode,
Type *Ty) const {
@ -17543,12 +17552,12 @@ X86VectorTargetTransformInfo::getArithmeticInstrCost(unsigned Opcode,
};
// Look for AVX1 lowering tricks.
if (ST.hasAVX())
for (unsigned int i = 0, e = array_lengthof(AVX1CostTable); i < e; ++i) {
if (AVX1CostTable[i].ISD == ISD && AVX1CostTable[i].Type == LT.second)
return LT.first * AVX1CostTable[i].Cost;
}
if (ST.hasAVX()) {
int Idx = FindInTable(AVX1CostTable, array_lengthof(AVX1CostTable), ISD,
LT.second);
if (Idx != -1)
return LT.first * AVX1CostTable[Idx].Cost;
}
// Fallback to the default implementation.
return VectorTargetTransformImpl::getArithmeticInstrCost(Opcode, Ty);
}
@ -17558,7 +17567,7 @@ X86VectorTargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
unsigned Index) const {
assert(Val->isVectorTy() && "This must be a vector type");
if (Index != -1u) {
if (Index != -1U) {
// Legalize the type.
std::pair<unsigned, MVT> LT =
getTypeLegalizationCost(Val->getContext(), TLI->getValueType(Val));
@ -17579,3 +17588,67 @@ X86VectorTargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val,
return VectorTargetTransformImpl::getVectorInstrCost(Opcode, Val, Index);
}
unsigned X86VectorTargetTransformInfo::getCmpSelInstrCost(unsigned Opcode,
Type *ValTy,
Type *CondTy) const {
// Legalize the type.
std::pair<unsigned, MVT> LT =
getTypeLegalizationCost(ValTy->getContext(), TLI->getValueType(ValTy));
MVT MTy = LT.second;
int ISD = InstructionOpcodeToISD(Opcode);
assert(ISD && "Invalid opcode");
const X86Subtarget &ST =
TLI->getTargetMachine().getSubtarget<X86Subtarget>();
static const X86CostTblEntry SSE42CostTbl[] = {
{ ISD::SETCC, MVT::v2f64, 1 },
{ ISD::SETCC, MVT::v4f32, 1 },
{ ISD::SETCC, MVT::v2i64, 1 },
{ ISD::SETCC, MVT::v4i32, 1 },
{ ISD::SETCC, MVT::v8i16, 1 },
{ ISD::SETCC, MVT::v16i8, 1 },
};
static const X86CostTblEntry AVX1CostTbl[] = {
{ ISD::SETCC, MVT::v4f64, 1 },
{ ISD::SETCC, MVT::v8f32, 1 },
// AVX1 does not support 8-wide integer compare.
{ ISD::SETCC, MVT::v4i64, 4 },
{ ISD::SETCC, MVT::v8i32, 4 },
{ ISD::SETCC, MVT::v16i16, 4 },
{ ISD::SETCC, MVT::v32i8, 4 },
};
static const X86CostTblEntry AVX2CostTbl[] = {
{ ISD::SETCC, MVT::v4i64, 1 },
{ ISD::SETCC, MVT::v8i32, 1 },
{ ISD::SETCC, MVT::v16i16, 1 },
{ ISD::SETCC, MVT::v32i8, 1 },
};
if (ST.hasSSE42()) {
int Idx = FindInTable(SSE42CostTbl, array_lengthof(SSE42CostTbl), ISD, MTy);
if (Idx != -1)
return LT.first * SSE42CostTbl[Idx].Cost;
}
if (ST.hasAVX()) {
int Idx = FindInTable(AVX1CostTbl, array_lengthof(AVX1CostTbl), ISD, MTy);
if (Idx != -1)
return LT.first * AVX1CostTbl[Idx].Cost;
}
if (ST.hasAVX2()) {
int Idx = FindInTable(AVX2CostTbl, array_lengthof(AVX2CostTbl), ISD, MTy);
if (Idx != -1)
return LT.first * AVX2CostTbl[Idx].Cost;
}
return VectorTargetTransformImpl::getCmpSelInstrCost(Opcode, ValTy, CondTy);
}

View File

@ -957,8 +957,10 @@ namespace llvm {
virtual unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
unsigned Index) const;
};
unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
Type *CondTy) const;
};
}
#endif // X86ISELLOWERING_H

View File

@ -0,0 +1,42 @@
; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.8.0"
define i32 @cmp(i32 %arg) {
; -- floats --
;CHECK: cost of 1 {{.*}} fcmp
%A = fcmp olt <2 x float> undef, undef
;CHECK: cost of 1 {{.*}} fcmp
%B = fcmp olt <4 x float> undef, undef
;CHECK: cost of 1 {{.*}} fcmp
%C = fcmp olt <8 x float> undef, undef
;CHECK: cost of 1 {{.*}} fcmp
%D = fcmp olt <2 x double> undef, undef
;CHECK: cost of 1 {{.*}} fcmp
%E = fcmp olt <4 x double> undef, undef
; -- integers --
;CHECK: cost of 1 {{.*}} icmp
%F = icmp eq <16 x i8> undef, undef
;CHECK: cost of 1 {{.*}} icmp
%G = icmp eq <8 x i16> undef, undef
;CHECK: cost of 1 {{.*}} icmp
%H = icmp eq <4 x i32> undef, undef
;CHECK: cost of 1 {{.*}} icmp
%I = icmp eq <2 x i64> undef, undef
;CHECK: cost of 4 {{.*}} icmp
%J = icmp eq <4 x i64> undef, undef
;CHECK: cost of 4 {{.*}} icmp
%K = icmp eq <8 x i32> undef, undef
;CHECK: cost of 4 {{.*}} icmp
%L = icmp eq <16 x i16> undef, undef
;CHECK: cost of 4 {{.*}} icmp
%M = icmp eq <32 x i8> undef, undef
;CHECK: cost of 1 {{.*}} ret
ret i32 undef
}