]> granicus.if.org Git - llvm/commit
[SLP] Fix for PR31880: shuffle and vectorize repeated scalar ops on extracted elements
authorAlexey Bataev <a.bataev@hotmail.com>
Wed, 2 Aug 2017 13:25:26 +0000 (13:25 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Wed, 2 Aug 2017 13:25:26 +0000 (13:25 +0000)
commitb51029d1f125e9621b13de8c0ebff15087c008aa
treecf21f186a623d798225265a9c60d50140b243ac0
parentbb326e2526455f10c7c464c99c0ab3427096b6ab
[SLP] Fix for PR31880: shuffle and vectorize repeated scalar ops on extracted elements

Summary:
Currently most of the time vectors of extractelement instructions are
treated as scalars that must be gathered into vectors. But in some
cases, like when we have extractelement instructions from single vector
with different constant indeces or from 2 vectors of the same size, we
can treat this operations as shuffle of a single vector or blending of 2
vectors.
```
define <2 x i8> @g(<2 x i8> %x, <2 x i8> %y) {
  %x0 = extractelement <2 x i8> %x, i32 0
  %y1 = extractelement <2 x i8> %y, i32 1
  %x0x0 = mul i8 %x0, %x0
  %y1y1 = mul i8 %y1, %y1
  %ins1 = insertelement <2 x i8> undef, i8 %x0x0, i32 0
  %ins2 = insertelement <2 x i8> %ins1, i8 %y1y1, i32 1
  ret <2 x i8> %ins2
}
```
can be converted to something like
```
define <2 x i8> @g(<2 x i8> %x, <2 x i8> %y) {
  %1 = shufflevector <2 x i8> %x, <2 x i8> %y, <2 x i32> <i32 0, i32 3>
  %2 = mul <2 x i8> %1, %1
  ret <2 x i8> %2
}
```
Currently this type of conversion is considered as high cost
transformation.

Reviewers: mzolotukhin, delena, mkuper, hfinkel, RKSimon

Subscribers: ashahid, RKSimon, spatel, llvm-commits

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

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