[PATCH] Include legalization cost when computing scalarization cost

Arnold Schwaighofer aschwaighofer at apple.com
Thu Mar 6 18:48:54 PST 2014


On Mar 6, 2014, at 5:11 PM, Raul Silvera <rsilvera at google.com> wrote:
> Index: lib/CodeGen/BasicTargetTransformInfo.cpp
> ===================================================================
> --- lib/CodeGen/BasicTargetTransformInfo.cpp
> +++ lib/CodeGen/BasicTargetTransformInfo.cpp
> @@ -20,7 +20,6 @@
> #include "llvm/Analysis/TargetTransformInfo.h"
> #include "llvm/Target/TargetLowering.h"
> #include <utility>
> -
> using namespace llvm;
> 
> namespace {
> @@ -206,12 +205,19 @@
>                                             bool Extract) const {
>   assert (Ty->isVectorTy() && "Can only scalarize vectors");
>   unsigned Cost = 0;
> -
> -  for (int i = 0, e = Ty->getVectorNumElements(); i < e; ++i) {
> -    if (Insert)
> -      Cost += TopTTI->getVectorInstrCost(Instruction::InsertElement, Ty, i);
> -    if (Extract)
> -      Cost += TopTTI->getVectorInstrCost(Instruction::ExtractElement, Ty, i);
> +  VectorType *VecTy = cast<VectorType>(Ty);
> +  std::pair<unsigned, MVT> LT =
> +      getTLI()->getTypeLegalizationCost(VecTy->getElementType());
> +
> +  for (int i = 0, e = VecTy->getVectorNumElements(); i < e; ++i) {
> +    if (Insert) {
> +      Cost += LT.first *
> +              TopTTI->getVectorInstrCost(Instruction::InsertElement, VecTy, i);
> +    }
> +    if (Extract) {
> +      Cost += LT.first *
> +              TopTTI->getVectorInstrCost(Instruction::ExtractElement, VecTy, i);
> +    }

Why do we want to do it at this (higher) level? I think, getVectorInstrCost() should have included the type legalization cost of the scalar type.

unsigned BasicTTI::getVectorInstrCost(unsigned Opcode, Type *Val,
                                      unsigned Index) const {
    return getTLI().getTypeLegalizationCost(Ty->getScalarType()).second;
}




More information about the llvm-commits mailing list