Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7464,8 +7464,11 @@ // Generate a sequence of selects of the form: // SELECT(Mask3, In3, - // SELECT(Mask2, In2, - // ( ...))) + // SELECT(Mask2, In2, + // SELECT(Mask1, In1, + // In0))) + // Note that Mask0 is never used: lanes for which no path reaches this phi and + // are essentially undef are taken from In0. InnerLoopVectorizer::VectorParts Entry(State.UF); for (unsigned In = 0; In < NumIncoming; ++In) { for (unsigned Part = 0; Part < State.UF; ++Part) { Index: llvm/lib/Transforms/Vectorize/VPlan.h =================================================================== --- llvm/lib/Transforms/Vectorize/VPlan.h +++ llvm/lib/Transforms/Vectorize/VPlan.h @@ -929,16 +929,16 @@ /// The blend operation is a User of the incoming values and of their /// respective masks, ordered [I0, M0, I1, M1, ...]. Note that a single value - /// would be incoming with a full mask for which there is no VPValue. + /// might be incoming with a full mask for which there is no VPValue. VPUser User; public: VPBlendRecipe(PHINode *Phi, ArrayRef Operands) : VPRecipeBase(VPBlendSC), Phi(Phi), User(Operands) { - assert(((Operands.size() == 1) || - (Operands.size() > 2 && Operands.size() % 2 == 0)) && - "Expected either a single incoming value or a greater than two and " - "even number of operands"); + assert(Operands.size() > 0 && + ((Operands.size() == 1) || (Operands.size() % 2 == 0)) && + "Expected either a single incoming value or a positive even number " + "of operands"); } /// Method to support type inquiry through isa, cast, and dyn_cast. Index: llvm/test/Transforms/LoopVectorize/pr45525.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/LoopVectorize/pr45525.ll @@ -0,0 +1,58 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -loop-vectorize -S | FileCheck %s + +; Test case for PR45525. Checks that phi's with a single predecessor are supported. + +define void @main() { +; CHECK-LABEL: @main( +; CHECK-NEXT: bb.0: +; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]] +; CHECK: vector.ph: +; CHECK-NEXT: br label [[VECTOR_BODY:%.*]] +; CHECK: vector.body: +; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ] +; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> undef, i32 [[INDEX]], i32 0 +; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> undef, <4 x i32> zeroinitializer +; CHECK-NEXT: [[INDUCTION:%.*]] = add <4 x i32> [[BROADCAST_SPLAT]], +; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[INDEX]], 0 +; CHECK-NEXT: [[INDEX_NEXT]] = add i32 [[INDEX]], 4 +; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[INDEX_NEXT]], 32 +; CHECK-NEXT: br i1 [[TMP1]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop !0 +; CHECK: middle.block: +; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 32, 32 +; CHECK-NEXT: br i1 [[CMP_N]], label [[BB_4:%.*]], label [[SCALAR_PH]] +; CHECK: scalar.ph: +; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ 32, [[MIDDLE_BLOCK]] ], [ 0, [[BB_0:%.*]] ] +; CHECK-NEXT: br label [[BB_1:%.*]] +; CHECK: bb.1: +; CHECK-NEXT: [[V_LOOP_1814_0:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INC1290:%.*]], [[BB_3:%.*]] ] +; CHECK-NEXT: br i1 undef, label [[BB_3]], label [[BB_2:%.*]] +; CHECK: bb.2: +; CHECK-NEXT: [[COND9203:%.*]] = phi i32 [ undef, [[BB_1]] ] +; CHECK-NEXT: br label [[BB_3]] +; CHECK: bb.3: +; CHECK-NEXT: [[INC1290]] = add i32 [[V_LOOP_1814_0]], 1 +; CHECK-NEXT: [[CMP816:%.*]] = icmp ult i32 [[INC1290]], 32 +; CHECK-NEXT: br i1 [[CMP816]], label [[BB_1]], label [[BB_4]], !llvm.loop !2 +; CHECK: bb.4: +; CHECK-NEXT: ret void +; +bb.0: + br label %bb.1 + +bb.1: ; preds = %bb.3, %bb.0 + %v_loop_1814.0 = phi i32 [ 0, %bb.0 ], [ %inc1290, %bb.3 ] + br i1 undef, label %bb.3, label %bb.2 + +bb.2: ; preds = %bb.1 + %cond9203 = phi i32 [ undef, %bb.1 ] + br label %bb.3 + +bb.3: ; preds = %bb.2, %bb.1 + %inc1290 = add i32 %v_loop_1814.0, 1 + %cmp816 = icmp ult i32 %inc1290, 32 + br i1 %cmp816, label %bb.1, label %bb.4 + +bb.4: ; preds = %bb.3 + ret void +}