From b994f4cdbcb628f16698015d4a345744a02910c7 Mon Sep 17 00:00:00 2001 From: Guozhi Wei Date: Tue, 31 May 2016 20:41:19 +0000 Subject: [SLP] Pass in correct alignment when query memory access cost This patch fixes bug https://llvm.org/bugs/show_bug.cgi?id=27897. When query memory access cost, current SLP always passes in alignment value of 1 (unaligned), so it gets a very high cost of scalar memory access, and wrongly vectorize memory loads in the test case. It can be fixed by simply giving correct alignment. llvm-svn: 271333 --- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp') diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 30da577d0bd..57824434b1b 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -1726,16 +1726,20 @@ int BoUpSLP::getEntryCost(TreeEntry *E) { } case Instruction::Load: { // Cost of wide load - cost of scalar loads. + unsigned alignment = dyn_cast(VL0)->getAlignment(); int ScalarLdCost = VecTy->getNumElements() * - TTI->getMemoryOpCost(Instruction::Load, ScalarTy, 1, 0); - int VecLdCost = TTI->getMemoryOpCost(Instruction::Load, VecTy, 1, 0); + TTI->getMemoryOpCost(Instruction::Load, ScalarTy, alignment, 0); + int VecLdCost = TTI->getMemoryOpCost(Instruction::Load, + VecTy, alignment, 0); return VecLdCost - ScalarLdCost; } case Instruction::Store: { // We know that we can merge the stores. Calculate the cost. + unsigned alignment = dyn_cast(VL0)->getAlignment(); int ScalarStCost = VecTy->getNumElements() * - TTI->getMemoryOpCost(Instruction::Store, ScalarTy, 1, 0); - int VecStCost = TTI->getMemoryOpCost(Instruction::Store, VecTy, 1, 0); + TTI->getMemoryOpCost(Instruction::Store, ScalarTy, alignment, 0); + int VecStCost = TTI->getMemoryOpCost(Instruction::Store, + VecTy, alignment, 0); return VecStCost - ScalarStCost; } case Instruction::Call: { -- cgit v1.2.3