Skip to content

Commit b747d72

Browse files
committed
[LV] Fix PR45525: Incorrect assert in blend recipe
Fix an assert introduced in 41ed5d8: a phi with a single predecessor and a mask is a valid case which is already supported by the code. Differential Revision: https://reviews.llvm.org/D78115
1 parent 2cd0be0 commit b747d72

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7463,8 +7463,11 @@ void VPBlendRecipe::execute(VPTransformState &State) {
74637463

74647464
// Generate a sequence of selects of the form:
74657465
// SELECT(Mask3, In3,
7466-
// SELECT(Mask2, In2,
7467-
// ( ...)))
7466+
// SELECT(Mask2, In2,
7467+
// SELECT(Mask1, In1,
7468+
// In0)))
7469+
// Note that Mask0 is never used: lanes for which no path reaches this phi and
7470+
// are essentially undef are taken from In0.
74687471
InnerLoopVectorizer::VectorParts Entry(State.UF);
74697472
for (unsigned In = 0; In < NumIncoming; ++In) {
74707473
for (unsigned Part = 0; Part < State.UF; ++Part) {

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -929,16 +929,16 @@ class VPBlendRecipe : public VPRecipeBase {
929929

930930
/// The blend operation is a User of the incoming values and of their
931931
/// respective masks, ordered [I0, M0, I1, M1, ...]. Note that a single value
932-
/// would be incoming with a full mask for which there is no VPValue.
932+
/// might be incoming with a full mask for which there is no VPValue.
933933
VPUser User;
934934

935935
public:
936936
VPBlendRecipe(PHINode *Phi, ArrayRef<VPValue *> Operands)
937937
: VPRecipeBase(VPBlendSC), Phi(Phi), User(Operands) {
938-
assert(((Operands.size() == 1) ||
939-
(Operands.size() > 2 && Operands.size() % 2 == 0)) &&
940-
"Expected either a single incoming value or a greater than two and "
941-
"even number of operands");
938+
assert(Operands.size() > 0 &&
939+
((Operands.size() == 1) || (Operands.size() % 2 == 0)) &&
940+
"Expected either a single incoming value or a positive even number "
941+
"of operands");
942942
}
943943

944944
/// Method to support type inquiry through isa, cast, and dyn_cast.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; RUN: opt < %s -loop-vectorize -force-vector-width=4 -S | FileCheck %s
2+
3+
; Test case for PR45525. Checks that phi's with a single predecessor and a mask are supported.
4+
5+
define void @main(i1 %cond, i32* %arr) {
6+
; CHECK-LABEL: @main(
7+
; CHECK-NEXT: bb.0:
8+
; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
9+
; CHECK: vector.ph:
10+
; CHECK: br label [[VECTOR_BODY:%.*]]
11+
; CHECK: vector.body:
12+
; CHECK: [[VEC_IND:%.*]] = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
13+
; CHECK: [[TMP5:%.*]] = mul <4 x i32> [[VEC_IND]], <i32 3, i32 3, i32 3, i32 3>
14+
;
15+
bb.0:
16+
br label %bb.1
17+
18+
bb.1: ; preds = %bb.3, %bb.0
19+
%iv = phi i32 [ 0, %bb.0 ], [ %iv.next, %bb.3 ]
20+
br i1 %cond, label %bb.3, label %bb.2
21+
22+
bb.2: ; preds = %bb.1
23+
%single.pred = phi i32 [ %iv, %bb.1 ]
24+
%mult = mul i32 %single.pred, 3
25+
br label %bb.3
26+
27+
bb.3: ; preds = %bb.2, %bb.1
28+
%stored.value = phi i32 [ 7, %bb.1 ], [ %mult, %bb.2 ]
29+
%arrayidx = getelementptr inbounds i32, i32* %arr, i32 %iv
30+
store i32 %stored.value, i32* %arrayidx
31+
%iv.next = add i32 %iv, 1
32+
%continue = icmp ult i32 %iv.next, 32
33+
br i1 %continue, label %bb.1, label %bb.4
34+
35+
bb.4: ; preds = %bb.3
36+
ret void
37+
}

0 commit comments

Comments
 (0)