diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Target/TargetTransformImpl.cpp | 10 | ||||
-rw-r--r-- | lib/Target/X86/X86ISelLowering.cpp | 1 | ||||
-rw-r--r-- | lib/Transforms/Vectorize/LoopVectorize.cpp | 42 |
3 files changed, 31 insertions, 22 deletions
diff --git a/lib/Target/TargetTransformImpl.cpp b/lib/Target/TargetTransformImpl.cpp index 4320437020..1f568506d9 100644 --- a/lib/Target/TargetTransformImpl.cpp +++ b/lib/Target/TargetTransformImpl.cpp @@ -132,7 +132,6 @@ int VectorTargetTransformImpl::InstructionOpcodeToISD(unsigned Opcode) const { std::pair<unsigned, MVT> VectorTargetTransformImpl::getTypeLegalizationCost(Type *Ty) const { - LLVMContext &C = Ty->getContext(); EVT MTy = TLI->getValueType(Ty); @@ -271,7 +270,7 @@ unsigned VectorTargetTransformImpl::getCastInstrCost(unsigned Opcode, Type *Dst, return getScalarizationOverhead(Dst, true, true) + Num * Cost; } - // We already handled vector-to-vector and scalar-to-scalar conversions. This + // We already handled vector-to-vector and scalar-to-scalar conversions. This // is where we handle bitcast between vectors and scalars. We need to assume // that the conversion is scalarized in one way or another. if (Opcode == Instruction::BitCast) @@ -283,6 +282,7 @@ unsigned VectorTargetTransformImpl::getCastInstrCost(unsigned Opcode, Type *Dst, } unsigned VectorTargetTransformImpl::getCFInstrCost(unsigned Opcode) const { + // Branches are assumed to be predicted. return 0; } @@ -331,12 +331,6 @@ unsigned VectorTargetTransformImpl::getVectorInstrCost(unsigned Opcode, } unsigned -VectorTargetTransformImpl::getInstrCost(unsigned Opcode, Type *Ty1, - Type *Ty2) const { - return 1; -} - -unsigned VectorTargetTransformImpl::getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, unsigned AddressSpace) const { diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 262475e97f..b53a023a81 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -17988,7 +17988,6 @@ X86VectorTargetTransformInfo::getArithmeticInstrCost(unsigned Opcode, return VectorTargetTransformImpl::getArithmeticInstrCost(Opcode, Ty); } - unsigned X86VectorTargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src, unsigned Alignment, diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index f5ff79c0b9..5b1db0b9d1 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2080,17 +2080,23 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) { VectorTy = ToVectorTy(ValTy, VF); if (VF == 1) - return VTTI->getMemoryOpCost(I->getOpcode(), ValTy, + return VTTI->getMemoryOpCost(I->getOpcode(), VectorTy, SI->getAlignment(), SI->getPointerAddressSpace()); // Scalarized stores. if (!Legal->isConsecutivePtr(SI->getPointerOperand())) { unsigned Cost = 0; - unsigned ExtCost = VTTI->getInstrCost(Instruction::ExtractElement, - ValTy); - // The cost of extracting from the value vector. - Cost += VF * (ExtCost); + + // The cost of extracting from the value vector and pointer vector. + Type *PtrTy = ToVectorTy(I->getOperand(0)->getType(), VF); + for (unsigned i = 0; i < VF; ++i) { + Cost += VTTI->getVectorInstrCost(Instruction::ExtractElement, + VectorTy, i); + Cost += VTTI->getVectorInstrCost(Instruction::ExtractElement, + PtrTy, i); + } + // The cost of the scalar stores. Cost += VF * VTTI->getMemoryOpCost(I->getOpcode(), ValTy->getScalarType(), @@ -2107,16 +2113,25 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) { LoadInst *LI = cast<LoadInst>(I); if (VF == 1) - return VTTI->getMemoryOpCost(I->getOpcode(), RetTy, + return VTTI->getMemoryOpCost(I->getOpcode(), VectorTy, LI->getAlignment(), LI->getPointerAddressSpace()); // Scalarized loads. if (!Legal->isConsecutivePtr(LI->getPointerOperand())) { unsigned Cost = 0; - unsigned InCost = VTTI->getInstrCost(Instruction::InsertElement, RetTy); - // The cost of inserting the loaded value into the result vector. - Cost += VF * (InCost); + Type *PtrTy = ToVectorTy(I->getOperand(0)->getType(), VF); + + // The cost of extracting from the pointer vector. + for (unsigned i = 0; i < VF; ++i) + Cost += VTTI->getVectorInstrCost(Instruction::ExtractElement, + PtrTy, i); + + // The cost of inserting data to the result vector. + for (unsigned i = 0; i < VF; ++i) + Cost += VTTI->getVectorInstrCost(Instruction::InsertElement, + VectorTy, i); + // The cost of the scalar stores. Cost += VF * VTTI->getMemoryOpCost(I->getOpcode(), RetTy->getScalarType(), @@ -2169,18 +2184,19 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) { bool IsVoid = RetTy->isVoidTy(); unsigned InsCost = (IsVoid ? 0 : - VTTI->getInstrCost(Instruction::InsertElement, + VTTI->getVectorInstrCost(Instruction::InsertElement, VectorTy)); - unsigned ExtCost = VTTI->getInstrCost(Instruction::ExtractElement, + unsigned ExtCost = VTTI->getVectorInstrCost(Instruction::ExtractElement, VectorTy); // The cost of inserting the results plus extracting each one of the // operands. Cost += VF * (InsCost + ExtCost * I->getNumOperands()); - // The cost of executing VF copies of the scalar instruction. - Cost += VF * VTTI->getInstrCost(I->getOpcode(), RetTy); + // The cost of executing VF copies of the scalar instruction. This opcode + // is unknown. Assume that it is the same as 'mul'. + Cost += VF * VTTI->getArithmeticInstrCost(Instruction::Mul, VectorTy); return Cost; } }// end of switch. |