From b65ab9a410df7ec225862281930a40491e5965e0 Mon Sep 17 00:00:00 2001 From: Silviu Baranga Date: Mon, 3 Aug 2015 14:00:58 +0000 Subject: [PATCH] [TTI] Fix default costs for interleaved accesses Summary: Modify the cost calculation function for interleaved accesses to use the target-specific costs for insert/extract element and memory operations. This better models the case where the backend can't match the interleaved group, and we are forced to use a wide load and shuffle vectors. Interleaved accesses are not enabled by default, so this shouldn't cause a performance change. Reviewers: jmolloy Subscribers: jmolloy, llvm-commits Differential Revision: http://reviews.llvm.org/D11718 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243875 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/BasicTTIImpl.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/include/llvm/CodeGen/BasicTTIImpl.h b/include/llvm/CodeGen/BasicTTIImpl.h index 796a78c16ac..70c4b45776f 100644 --- a/include/llvm/CodeGen/BasicTTIImpl.h +++ b/include/llvm/CodeGen/BasicTTIImpl.h @@ -534,7 +534,8 @@ public: VectorType *SubVT = VectorType::get(VT->getElementType(), NumSubElts); // Firstly, the cost of load/store operation. - unsigned Cost = getMemoryOpCost(Opcode, VecTy, Alignment, AddressSpace); + unsigned Cost = static_cast(this)->getMemoryOpCost( + Opcode, VecTy, Alignment, AddressSpace); // Then plus the cost of interleave operation. if (Opcode == Instruction::Load) { @@ -549,18 +550,20 @@ public: assert(Indices.size() <= Factor && "Interleaved memory op has too many members"); + for (unsigned Index : Indices) { assert(Index < Factor && "Invalid index for interleaved memory op"); // Extract elements from loaded vector for each sub vector. for (unsigned i = 0; i < NumSubElts; i++) - Cost += getVectorInstrCost(Instruction::ExtractElement, VT, - Index + i * Factor); + Cost += static_cast(this)->getVectorInstrCost( + Instruction::ExtractElement, VT, Index + i * Factor); } unsigned InsSubCost = 0; for (unsigned i = 0; i < NumSubElts; i++) - InsSubCost += getVectorInstrCost(Instruction::InsertElement, SubVT, i); + InsSubCost += static_cast(this)->getVectorInstrCost( + Instruction::InsertElement, SubVT, i); Cost += Indices.size() * InsSubCost; } else { @@ -575,12 +578,13 @@ public: unsigned ExtSubCost = 0; for (unsigned i = 0; i < NumSubElts; i++) - ExtSubCost += getVectorInstrCost(Instruction::ExtractElement, SubVT, i); - - Cost += Factor * ExtSubCost; + ExtSubCost += static_cast(this)->getVectorInstrCost( + Instruction::ExtractElement, SubVT, i); + Cost += ExtSubCost * Factor; for (unsigned i = 0; i < NumElts; i++) - Cost += getVectorInstrCost(Instruction::InsertElement, VT, i); + Cost += static_cast(this) + ->getVectorInstrCost(Instruction::InsertElement, VT, i); } return Cost; -- 2.34.1