LoopVectorize: Emit reductions as log2(vectorsize) shuffles + vector ops instead...
authorBenjamin Kramer <benny.kra@googlemail.com>
Tue, 18 Dec 2012 18:40:20 +0000 (18:40 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Tue, 18 Dec 2012 18:40:20 +0000 (18:40 +0000)
commit0ef0e2e6d0a45cdbc792eee9d76f0a4b7cda5c8f
tree0c223bedc03ed2a4e4371293246e4cb551d17a10
parent968b667e27d7fc9a5bf5da52191a7af629e174dc
LoopVectorize: Emit reductions as log2(vectorsize) shuffles + vector ops instead of scalar operations.

For example on x86 with SSE4.2 a <8 x i8> add reduction becomes
movdqa %xmm0, %xmm1
movhlps %xmm1, %xmm1            ## xmm1 = xmm1[1,1]
paddw %xmm0, %xmm1
pshufd $1, %xmm1, %xmm0        ## xmm0 = xmm1[1,0,0,0]
paddw %xmm1, %xmm0
phaddw %xmm0, %xmm0
pextrb $0, %xmm0, %edx

instead of
pextrb $2, %xmm0, %esi
pextrb $0, %xmm0, %edx
addb %sil, %dl
pextrb $4, %xmm0, %esi
addb %dl, %sil
pextrb $6, %xmm0, %edx
addb %sil, %dl
pextrb $8, %xmm0, %esi
addb %dl, %sil
pextrb $10, %xmm0, %edi
pextrb $14, %xmm0, %edx
addb %sil, %dil
pextrb $12, %xmm0, %esi
addb %dil, %sil
addb %sil, %dl

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170439 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Vectorize/LoopVectorize.cpp
test/Transforms/LoopVectorize/reduction.ll