Skip to content

Commit 2256d00

Browse files
authored
[SLP][REVEC] Use VL.front()->getType() as ScalarTy. (#102437)
VL.front()->getType() may be FixedVectorType when revec is enabled. Fix "Expected item in MinBWs.".
1 parent 4197386 commit 2256d00

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12586,8 +12586,15 @@ Value *BoUpSLP::vectorizeOperand(TreeEntry *E, unsigned NodeIdx,
1258612586
}
1258712587
if (IsSameVE) {
1258812588
auto FinalShuffle = [&](Value *V, ArrayRef<int> Mask) {
12589+
// V may be affected by MinBWs.
12590+
// We want ShuffleInstructionBuilder to correctly support REVEC. The key
12591+
// factor is the number of elements, not their type.
12592+
Type *ScalarTy = cast<VectorType>(V->getType())->getElementType();
12593+
unsigned NumElements = getNumElements(VL.front()->getType());
1258912594
ShuffleInstructionBuilder ShuffleBuilder(
12590-
cast<VectorType>(V->getType())->getElementType(), Builder, *this);
12595+
NumElements != 1 ? FixedVectorType::get(ScalarTy, NumElements)
12596+
: ScalarTy,
12597+
Builder, *this);
1259112598
ShuffleBuilder.add(V, Mask);
1259212599
return ShuffleBuilder.finalize(std::nullopt);
1259312600
};

llvm/test/Transforms/SLPVectorizer/revec.ll

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,37 @@ define void @test7() {
238238
store <8 x i16> %3, ptr null, align 2
239239
ret void
240240
}
241+
242+
define void @test8() {
243+
; CHECK-LABEL: @test8(
244+
; CHECK-NEXT: entry:
245+
; CHECK-NEXT: [[TMP0:%.*]] = call <8 x float> @llvm.vector.insert.v8f32.v2f32(<8 x float> poison, <2 x float> zeroinitializer, i64 0)
246+
; CHECK-NEXT: [[TMP1:%.*]] = call <8 x float> @llvm.vector.insert.v8f32.v2f32(<8 x float> [[TMP0]], <2 x float> zeroinitializer, i64 2)
247+
; CHECK-NEXT: [[TMP2:%.*]] = call <8 x float> @llvm.vector.insert.v8f32.v2f32(<8 x float> [[TMP1]], <2 x float> zeroinitializer, i64 4)
248+
; CHECK-NEXT: [[TMP3:%.*]] = call <8 x float> @llvm.vector.insert.v8f32.v2f32(<8 x float> [[TMP2]], <2 x float> zeroinitializer, i64 6)
249+
; CHECK-NEXT: [[TMP4:%.*]] = call <4 x float> @llvm.vector.insert.v4f32.v2f32(<4 x float> poison, <2 x float> zeroinitializer, i64 0)
250+
; CHECK-NEXT: [[TMP5:%.*]] = call <4 x float> @llvm.vector.insert.v4f32.v2f32(<4 x float> [[TMP4]], <2 x float> zeroinitializer, i64 2)
251+
; CHECK-NEXT: br i1 false, label [[FOR0:%.*]], label [[FOR_BODY:%.*]]
252+
; CHECK: for0:
253+
; CHECK-NEXT: [[TMP6:%.*]] = phi <8 x float> [ [[TMP3]], [[ENTRY:%.*]] ], [ [[TMP8:%.*]], [[FOR_BODY]] ]
254+
; CHECK-NEXT: ret void
255+
; CHECK: for.body:
256+
; CHECK-NEXT: [[TMP7:%.*]] = phi <4 x float> [ [[TMP7]], [[FOR_BODY]] ], [ [[TMP5]], [[ENTRY]] ]
257+
; CHECK-NEXT: [[TMP8]] = shufflevector <4 x float> [[TMP7]], <4 x float> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 0, i32 1, i32 2, i32 3>
258+
; CHECK-NEXT: br i1 false, label [[FOR0]], label [[FOR_BODY]]
259+
;
260+
entry:
261+
br i1 false, label %for0, label %for.body
262+
263+
for0:
264+
%0 = phi <2 x float> [ zeroinitializer, %entry ], [ %4, %for.body ]
265+
%1 = phi <2 x float> [ zeroinitializer, %entry ], [ %5, %for.body ]
266+
%2 = phi <2 x float> [ zeroinitializer, %entry ], [ %4, %for.body ]
267+
%3 = phi <2 x float> [ zeroinitializer, %entry ], [ %5, %for.body ]
268+
ret void
269+
270+
for.body:
271+
%4 = phi <2 x float> [ %4, %for.body ], [ zeroinitializer, %entry ]
272+
%5 = phi <2 x float> [ %5, %for.body ], [ zeroinitializer, %entry ]
273+
br i1 false, label %for0, label %for.body
274+
}

0 commit comments

Comments
 (0)