Skip to content

Commit ffb2e4c

Browse files
committed
[SLP][REVEC] Merge multiple shufflevectors. instcombine cannot do this
well.
1 parent 7e5e17f commit ffb2e4c

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13967,9 +13967,16 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
1396713967
LLVM_DEBUG(dbgs() << "SLP: Diamond merged for " << *VL0 << ".\n");
1396813968
return E->VectorizedValue;
1396913969
}
13970-
// The current shufflevector usage always duplicate the source.
13971-
V = Builder.CreateShuffleVector(Src,
13972-
calculateShufflevectorMask(E->Scalars));
13970+
assert(isa<ShuffleVectorInst>(Src) &&
13971+
"Not supported shufflevector usage.");
13972+
ShuffleVectorInst *SVSrc = cast<ShuffleVectorInst>(Src);
13973+
assert(isa<PoisonValue>(SVSrc->getOperand(1)) &&
13974+
"Not supported shufflevector usage.");
13975+
SmallVector<int> ThisMask(calculateShufflevectorMask(E->Scalars));
13976+
SmallVector<int> NewMask(ThisMask.size());
13977+
transform(ThisMask, NewMask.begin(),
13978+
[&SVSrc](int Mask) { return SVSrc->getShuffleMask()[Mask]; });
13979+
V = Builder.CreateShuffleVector(SVSrc->getOperand(0), NewMask);
1397313980
propagateIRFlags(V, E->Scalars, VL0);
1397413981
} else {
1397513982
assert(E->isAltShuffle() &&

llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ define void @test2(ptr %in, ptr %out) {
3535
; CHECK-NEXT: entry:
3636
; CHECK-NEXT: [[TMP0:%.*]] = load <8 x i32>, ptr [[IN:%.*]], align 1
3737
; CHECK-NEXT: [[TMP1:%.*]] = zext <8 x i32> [[TMP0]] to <8 x i64>
38-
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <8 x i64> [[TMP1]], <8 x i64> poison, <16 x i32> <i32 poison, i32 poison, i32 2, i32 3, i32 0, i32 1, i32 poison, i32 poison, i32 4, i32 5, i32 poison, i32 poison, i32 poison, i32 poison, i32 6, i32 7>
39-
; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <16 x i64> [[TMP2]], <16 x i64> poison, <8 x i32> <i32 2, i32 3, i32 4, i32 5, i32 8, i32 9, i32 14, i32 15>
40-
; CHECK-NEXT: store <8 x i64> [[TMP3]], ptr [[OUT:%.*]], align 8
38+
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <8 x i64> [[TMP1]], <8 x i64> poison, <8 x i32> <i32 2, i32 3, i32 0, i32 1, i32 4, i32 5, i32 6, i32 7>
39+
; CHECK-NEXT: store <8 x i64> [[TMP2]], ptr [[OUT:%.*]], align 8
4140
; CHECK-NEXT: ret void
4241
;
4342
entry:
@@ -64,9 +63,8 @@ entry:
6463
define void @test3(<16 x i32> %0, ptr %out) {
6564
; CHECK-LABEL: @test3(
6665
; CHECK-NEXT: entry:
67-
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <16 x i32> [[TMP0:%.*]], <16 x i32> poison, <64 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 12, i32 13, i32 14, i32 15, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 8, i32 9, i32 10, i32 11, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 4, i32 5, i32 6, i32 7, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
68-
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <64 x i32> [[TMP1]], <64 x i32> poison, <16 x i32> <i32 12, i32 13, i32 14, i32 15, i32 24, i32 25, i32 26, i32 27, i32 36, i32 37, i32 38, i32 39, i32 48, i32 49, i32 50, i32 51>
69-
; CHECK-NEXT: store <16 x i32> [[TMP2]], ptr [[OUT:%.*]], align 4
66+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <16 x i32> [[TMP0:%.*]], <16 x i32> poison, <16 x i32> <i32 12, i32 13, i32 14, i32 15, i32 8, i32 9, i32 10, i32 11, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3>
67+
; CHECK-NEXT: store <16 x i32> [[TMP1]], ptr [[OUT:%.*]], align 4
7068
; CHECK-NEXT: ret void
7169
;
7270
entry:

0 commit comments

Comments
 (0)