Skip to content

Commit c6091cd

Browse files
authored
[SLP][REVEC] Make shufflevector can be vectorized with ReorderIndices and ReuseShuffleIndices. (llvm#114965)
1 parent 70bc12e commit c6091cd

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15645,9 +15645,6 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
1564515645
case Instruction::ShuffleVector: {
1564615646
Value *V;
1564715647
if (SLPReVec && !E->isAltShuffle()) {
15648-
assert(E->ReuseShuffleIndices.empty() &&
15649-
"Not support ReuseShuffleIndices yet.");
15650-
assert(E->ReorderIndices.empty() && "Not support ReorderIndices yet.");
1565115648
setInsertPointAfterBundle(E);
1565215649
Value *Src = vectorizeOperand(E, 0, PostponedPHIs);
1565315650
if (E->VectorizedValue) {
@@ -15665,6 +15662,9 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
1566515662
[&SVSrc](int Mask) { return SVSrc->getShuffleMask()[Mask]; });
1566615663
V = Builder.CreateShuffleVector(SVSrc->getOperand(0), NewMask);
1566715664
propagateIRFlags(V, E->Scalars, VL0);
15665+
if (auto *I = dyn_cast<Instruction>(V))
15666+
V = propagateMetadata(I, E->Scalars);
15667+
V = FinalShuffle(V, E);
1566815668
} else {
1566915669
assert(E->isAltShuffle() &&
1567015670
((Instruction::isBinaryOp(E->getOpcode()) &&
@@ -15795,11 +15795,11 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
1579515795
transformScalarShuffleIndiciesToVector(VecTy->getNumElements(), Mask);
1579615796
}
1579715797
V = Builder.CreateShuffleVector(V0, V1, Mask);
15798-
}
15799-
if (auto *I = dyn_cast<Instruction>(V)) {
15800-
V = propagateMetadata(I, E->Scalars);
15801-
GatherShuffleExtractSeq.insert(I);
15802-
CSEBlocks.insert(I->getParent());
15798+
if (auto *I = dyn_cast<Instruction>(V)) {
15799+
V = propagateMetadata(I, E->Scalars);
15800+
GatherShuffleExtractSeq.insert(I);
15801+
CSEBlocks.insert(I->getParent());
15802+
}
1580315803
}
1580415804

1580515805
E->VectorizedValue = V;

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,26 @@ entry:
8282
store <4 x i32> %4, ptr %8, align 4
8383
ret void
8484
}
85+
86+
define void @test4(ptr %in, ptr %out) {
87+
; CHECK-LABEL: @test4(
88+
; CHECK-NEXT: entry:
89+
; CHECK-NEXT: [[TMP0:%.*]] = load <8 x i32>, ptr [[IN:%.*]], align 4
90+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[TMP0]], <8 x i32> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
91+
; CHECK-NEXT: store <16 x i32> [[TMP1]], ptr [[OUT:%.*]], align 4
92+
; CHECK-NEXT: ret void
93+
;
94+
entry:
95+
%0 = load <8 x i32>, ptr %in, align 4
96+
%1 = shufflevector <8 x i32> %0, <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
97+
%2 = shufflevector <8 x i32> %0, <8 x i32> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
98+
%3 = getelementptr inbounds i32, ptr %out, i64 0
99+
%4 = getelementptr inbounds i32, ptr %out, i64 4
100+
%5 = getelementptr inbounds i32, ptr %out, i64 8
101+
%6 = getelementptr inbounds i32, ptr %out, i64 12
102+
store <4 x i32> %1, ptr %3, align 4
103+
store <4 x i32> %2, ptr %4, align 4
104+
store <4 x i32> %1, ptr %5, align 4
105+
store <4 x i32> %2, ptr %6, align 4
106+
ret void
107+
}

0 commit comments

Comments
 (0)