@@ -143,6 +143,43 @@ TEST_F(VPVerifierTest, VPBlendUseBeforeDefDifferentBB) {
143143 delete Phi;
144144}
145145
146+ TEST_F (VPVerifierTest, VPPhiIncomingValueDoesntDominateIncomingBlock) {
147+ VPlan &Plan = getPlan ();
148+ IntegerType *Int32 = IntegerType::get (C, 32 );
149+ VPValue *Zero = Plan.getOrAddLiveIn (ConstantInt::get (Int32, 0 ));
150+
151+ VPBasicBlock *VPBB1 = Plan.getEntry ();
152+ VPBasicBlock *VPBB2 = Plan.createVPBasicBlock (" " );
153+ VPBasicBlock *VPBB3 = Plan.createVPBasicBlock (" " );
154+
155+ VPInstruction *DefI = new VPInstruction (Instruction::Add, {Zero});
156+ VPPhi *Phi = new VPPhi ({DefI}, {});
157+ VPBB2->appendRecipe (Phi);
158+ VPBB2->appendRecipe (DefI);
159+ auto *CanIV = new VPCanonicalIVPHIRecipe (Zero, {});
160+ VPBB3->appendRecipe (CanIV);
161+
162+ VPRegionBlock *R1 = Plan.createVPRegionBlock (VPBB3, VPBB3, " R1" );
163+ VPBlockUtils::connectBlocks (VPBB1, VPBB2);
164+ VPBlockUtils::connectBlocks (VPBB2, R1);
165+ #if GTEST_HAS_STREAM_REDIRECTION
166+ ::testing::internal::CaptureStderr ();
167+ #endif
168+ EXPECT_FALSE (verifyVPlanIsValid (Plan));
169+ #if GTEST_HAS_STREAM_REDIRECTION
170+ #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
171+ EXPECT_STREQ (" Incoming def at index 0 does not dominate incoming block!\n "
172+ " EMIT vp<%2> = add ir<0>\n "
173+ " does not dominate preheader for\n "
174+ " EMIT vp<%1> = phi [ vp<%2>, preheader ]" ,
175+ ::testing::internal::GetCapturedStderr ().c_str());
176+ #else
177+ EXPECT_STREQ (" Use before def!\n " ,
178+ ::testing::internal::GetCapturedStderr ().c_str());
179+ #endif
180+ #endif
181+ }
182+
146183TEST_F (VPVerifierTest, DuplicateSuccessorsOutsideRegion) {
147184 VPlan &Plan = getPlan ();
148185 VPValue *Zero = Plan.getOrAddLiveIn (ConstantInt::get (Type::getInt32Ty (C), 0 ));
0 commit comments