Skip to content

Commit f71ea4b

Browse files
authored
[SLP][REVEC] reorderNodeWithReuses should not be called if all users of a TreeEntry are ShuffleVectorInst. (#118260)
1 parent a2cb208 commit f71ea4b

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -6073,6 +6073,23 @@ void BoUpSLP::reorderTopToBottom() {
60736073
TE->Scalars.size();
60746074
}) &&
60756075
"All users must be of VF size.");
6076+
if (SLPReVec) {
6077+
assert(SLPReVec && "Only supported by REVEC.");
6078+
// ShuffleVectorInst does not do reorderOperands (and it should not
6079+
// because ShuffleVectorInst supports only a limited set of
6080+
// patterns). Only do reorderNodeWithReuses if all of the users are
6081+
// not ShuffleVectorInst.
6082+
if (all_of(TE->UserTreeIndices, [&](const EdgeInfo &EI) {
6083+
return isa<ShuffleVectorInst>(EI.UserTE->getMainOp());
6084+
}))
6085+
continue;
6086+
assert(none_of(TE->UserTreeIndices,
6087+
[&](const EdgeInfo &EI) {
6088+
return isa<ShuffleVectorInst>(
6089+
EI.UserTE->getMainOp());
6090+
}) &&
6091+
"Does not know how to reorder.");
6092+
}
60766093
// Update ordering of the operands with the smaller VF than the given
60776094
// one.
60786095
reorderNodeWithReuses(*TE, Mask);

llvm/test/Transforms/SLPVectorizer/revec.ll

+34
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,37 @@ for.end.loopexit:
447447
store <4 x i32> %4, ptr %out2, align 4
448448
ret void
449449
}
450+
451+
define void @test14(<8 x i1> %0) {
452+
; CHECK-LABEL: @test14(
453+
; CHECK-NEXT: entry:
454+
; CHECK-NEXT: [[TMP1:%.*]] = call <16 x i1> @llvm.vector.insert.v16i1.v8i1(<16 x i1> poison, <8 x i1> [[TMP0:%.*]], i64 0)
455+
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <16 x i1> [[TMP1]], <16 x i1> 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>
456+
; CHECK-NEXT: [[TMP3:%.*]] = sext <16 x i1> [[TMP2]] to <16 x i16>
457+
; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <16 x i16> [[TMP3]], <16 x i16> poison, <32 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, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
458+
; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <16 x i16> [[TMP3]], <16 x i16> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
459+
; CHECK-NEXT: [[TMP6:%.*]] = shufflevector <16 x i16> [[TMP3]], <16 x i16> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 4, i32 5, i32 6, i32 7>
460+
; CHECK-NEXT: br label [[FOR_END_LOOPEXIT:%.*]]
461+
; CHECK: for.end.loopexit:
462+
; CHECK-NEXT: [[TMP7:%.*]] = phi <16 x i16> [ [[TMP6]], [[ENTRY:%.*]] ]
463+
; CHECK-NEXT: [[TMP8:%.*]] = call <4 x i16> @llvm.vector.extract.v4i16.v16i16(<16 x i16> [[TMP7]], i64 12)
464+
; CHECK-NEXT: [[OR0:%.*]] = or <4 x i16> [[TMP8]], zeroinitializer
465+
; CHECK-NEXT: ret void
466+
;
467+
entry:
468+
%sext0 = sext <8 x i1> %0 to <8 x i16>
469+
%sext1 = sext <8 x i1> %0 to <8 x i16>
470+
%1 = shufflevector <8 x i16> %sext0, <8 x i16> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
471+
%2 = shufflevector <8 x i16> %sext0, <8 x i16> zeroinitializer, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
472+
%3 = shufflevector <8 x i16> %sext1, <8 x i16> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
473+
%4 = shufflevector <8 x i16> %sext1, <8 x i16> zeroinitializer, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
474+
br label %for.end.loopexit
475+
476+
for.end.loopexit:
477+
%phi0 = phi <4 x i16> [ %1, %entry ]
478+
%phi1 = phi <4 x i16> [ %2, %entry ]
479+
%phi2 = phi <4 x i16> [ %3, %entry ]
480+
%phi3 = phi <4 x i16> [ %4, %entry ]
481+
%or0 = or <4 x i16> %phi1, zeroinitializer
482+
ret void
483+
}

0 commit comments

Comments
 (0)