From a4ab5290e6808c54aff178d465d533e4eba53feb Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Mon, 5 Nov 2012 21:12:13 +0000 Subject: [PATCH] Cost Model: Normalize the insert/extract index when splitting types git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167402 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86ISelLowering.cpp | 23 ++++++++++++++++--- .../CostModel/X86/insert-extract-at-zero.ll | 7 ++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 575d30df2e0..a42b25b65f7 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -17556,9 +17556,26 @@ X86VectorTargetTransformInfo::getArithmeticInstrCost(unsigned Opcode, unsigned X86VectorTargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) const { - // Floating point scalars are already located in index #0. - if (Val->getScalarType()->isFloatingPointTy() && Index == 0) - return 0; + assert(Val->isVectorTy() && "This must be a vector type"); + + if (Index != -1) { + // Legalize the type. + std::pair LT = + getTypeLegalizationCost(Val->getContext(), TLI->getValueType(Val)); + + // This type is legalized to a scalar type. + if (!LT.second.isVector()) + return 0; + + // The type may be split. Normalize the index to the new type. + unsigned Width = LT.second.getVectorNumElements(); + Index = Index % Width; + + // Floating point scalars are already located in index #0. + if (Val->getScalarType()->isFloatingPointTy() && Index == 0) + return 0; + } + return VectorTargetTransformImpl::getVectorInstrCost(Opcode, Val, Index); } diff --git a/test/Analysis/CostModel/X86/insert-extract-at-zero.ll b/test/Analysis/CostModel/X86/insert-extract-at-zero.ll index eea5b601d01..87bf7c488b9 100644 --- a/test/Analysis/CostModel/X86/insert-extract-at-zero.ll +++ b/test/Analysis/CostModel/X86/insert-extract-at-zero.ll @@ -29,5 +29,12 @@ define i32 @insert-extract-at-zero-idx(i32 %arg, float %fl) { ;CHECK: cost of 0 {{.*}} insert %J = insertelement <4 x double> undef, double undef, i32 0 + ;CHECK: cost of 0 {{.*}} insert + %K = insertelement <8 x double> undef, double undef, i32 4 + ;CHECK: cost of 0 {{.*}} insert + %L = insertelement <16 x double> undef, double undef, i32 8 + ;CHECK: cost of 1 {{.*}} insert + %M = insertelement <16 x double> undef, double undef, i32 9 ret i32 0 } + -- 2.34.1