diff options
author | Nadav Rotem <nrotem@apple.com> | 2013-06-19 15:57:29 +0000 |
---|---|---|
committer | Nadav Rotem <nrotem@apple.com> | 2013-06-19 15:57:29 +0000 |
commit | 86e848c849e21f0d0009aeadbe71a8ab6b4e9ef2 (patch) | |
tree | e57b63cb696ace5749820cfde9ed6b1a3813c1f6 | |
parent | 18e8cf433528f103e7e1022b2b7a6b92bc037c41 (diff) | |
download | bcm5719-llvm-86e848c849e21f0d0009aeadbe71a8ab6b4e9ef2.tar.gz bcm5719-llvm-86e848c849e21f0d0009aeadbe71a8ab6b4e9ef2.zip |
SLPVectorizer: start constructing chains at stores that are not power of two.
The type <3 x i8> is a common in graphics and we want to be able to vectorize it.
This changes accelerates bullet by 12% and 471_omnetpp by 5%.
llvm-svn: 184317
-rw-r--r-- | llvm/lib/Transforms/Vectorize/VecUtils.cpp | 20 | ||||
-rw-r--r-- | llvm/test/Transforms/SLPVectorizer/X86/odd_store.ll | 46 |
2 files changed, 63 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Vectorize/VecUtils.cpp b/llvm/lib/Transforms/Vectorize/VecUtils.cpp index 2f6b7df21b6..1e97ed400be 100644 --- a/llvm/lib/Transforms/Vectorize/VecUtils.cpp +++ b/llvm/lib/Transforms/Vectorize/VecUtils.cpp @@ -104,6 +104,8 @@ bool BoUpSLP::isConsecutiveAccess(Value *A, Value *B) { } bool BoUpSLP::vectorizeStoreChain(ArrayRef<Value *> Chain, int CostThreshold) { + unsigned ChainLen = Chain.size(); + DEBUG(dbgs()<<"SLP: Analyzing a store chain of length " <<ChainLen<< "\n"); Type *StoreTy = cast<StoreInst>(Chain[0])->getValueOperand()->getType(); unsigned Sz = DL->getTypeSizeInBits(StoreTy); unsigned VF = MinVecRegSize / Sz; @@ -112,8 +114,8 @@ bool BoUpSLP::vectorizeStoreChain(ArrayRef<Value *> Chain, int CostThreshold) { bool Changed = false; // Look for profitable vectorizable trees at all offsets, starting at zero. - for (unsigned i = 0, e = Chain.size(); i < e; ++i) { - if (i + VF > e) return Changed; + for (unsigned i = 0, e = ChainLen; i < e; ++i) { + if (i + VF > e) break; DEBUG(dbgs()<<"SLP: Analyzing " << VF << " stores at offset "<< i << "\n"); ArrayRef<Value *> Operands = Chain.slice(i, VF); @@ -128,7 +130,19 @@ bool BoUpSLP::vectorizeStoreChain(ArrayRef<Value *> Chain, int CostThreshold) { } } - return Changed; + if (Changed) + return true; + + int Cost = getTreeCost(Chain); + if (Cost < CostThreshold) { + DEBUG(dbgs() << "SLP: Found store chain cost = "<< Cost <<" for size = " << + ChainLen << "\n"); + Builder.SetInsertPoint(getInsertionPoint(getLastIndex(Chain, ChainLen))); + vectorizeTree(Chain, ChainLen); + return true; + } + + return false; } bool BoUpSLP::vectorizeStores(ArrayRef<StoreInst *> Stores, int costThreshold) { diff --git a/llvm/test/Transforms/SLPVectorizer/X86/odd_store.ll b/llvm/test/Transforms/SLPVectorizer/X86/odd_store.ll new file mode 100644 index 00000000000..cb2b6862990 --- /dev/null +++ b/llvm/test/Transforms/SLPVectorizer/X86/odd_store.ll @@ -0,0 +1,46 @@ +; RUN: opt < %s -basicaa -slp-vectorizer -dce -S -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.8.0" + +;int foo(char * restrict A, float * restrict B, float T) { +; A[0] = (T * B[10] + 4.0); +; A[1] = (T * B[11] + 5.0); +; A[2] = (T * B[12] + 6.0); +;} + +;CHECK: @foo +;CHECK: load <3 x float> +;CHECK: fmul <3 x float> +;CHECK: fpext <3 x float> +;CHECK: fadd <3 x double> +;CHECK: fptosi <3 x double> +;CHECK: store <3 x i8> +;CHECK: ret +define i32 @foo(i8* noalias nocapture %A, float* noalias nocapture %B, float %T) { + %1 = getelementptr inbounds float* %B, i64 10 + %2 = load float* %1, align 4 + %3 = fmul float %2, %T + %4 = fpext float %3 to double + %5 = fadd double %4, 4.000000e+00 + %6 = fptosi double %5 to i8 + store i8 %6, i8* %A, align 1 + %7 = getelementptr inbounds float* %B, i64 11 + %8 = load float* %7, align 4 + %9 = fmul float %8, %T + %10 = fpext float %9 to double + %11 = fadd double %10, 5.000000e+00 + %12 = fptosi double %11 to i8 + %13 = getelementptr inbounds i8* %A, i64 1 + store i8 %12, i8* %13, align 1 + %14 = getelementptr inbounds float* %B, i64 12 + %15 = load float* %14, align 4 + %16 = fmul float %15, %T + %17 = fpext float %16 to double + %18 = fadd double %17, 6.000000e+00 + %19 = fptosi double %18 to i8 + %20 = getelementptr inbounds i8* %A, i64 2 + store i8 %19, i8* %20, align 1 + ret i32 undef +} + |