OSDN Git Service

[SLP] Fix for PR31879: vectorize repeated scalar ops that don't get put
authorAlexey Bataev <a.bataev@hotmail.com>
Tue, 14 Feb 2017 15:20:48 +0000 (15:20 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Tue, 14 Feb 2017 15:20:48 +0000 (15:20 +0000)
commit2cc74041bd9af6036483699d0a9d8ee7f9f49b9d
treef6da33b4057a165943248694b01190b8f35c746d
parent90b785146d1146932624753ba497c8ddf0f1a1e6
[SLP] Fix for PR31879: vectorize repeated scalar ops that don't get put
back into a vector

Previously the cost of the existing ExtractElement/ExtractValue
instructions was considered as a dead cost only if it was detected that
they have only one use. But these instructions may be considered
dead also if users of the instructions are also going to be vectorized,
like:
```
%x0 = extractelement <2 x float> %x, i32 0
%x1 = extractelement <2 x float> %x, i32 1
%x0x0 = fmul float %x0, %x0
%x1x1 = fmul float %x1, %x1
%add = fadd float %x0x0, %x1x1
```
This can be transformed to
```
%1 = fmul <2 x float> %x, %x
%2 = extractelement <2 x float> %1, i32 0
%3 = extractelement <2 x float> %1, i32 1
%add = fadd float %2, %3
```
because though `%x0` and `%x1` have 2 users each other, these users are
part of the vectorized tree and we can consider these `extractelement`
instructions as dead.

Differential Revision: https://reviews.llvm.org/D29900

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295056 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Vectorize/SLPVectorizer.cpp
test/Transforms/SLPVectorizer/X86/extractelement.ll