@@ -53,14 +53,10 @@ TEST_F(VPlanHCFGTest, testBuildHCFGInnerLoop) {
5353  VPBasicBlock *VecBB = Plan->getVectorLoopRegion ()->getEntryBasicBlock ();
5454  EXPECT_EQ (7u , VecBB->size ());
5555  EXPECT_EQ (0u , VecBB->getNumPredecessors ());
56-   EXPECT_EQ (1u , VecBB->getNumSuccessors ());
56+   EXPECT_EQ (0u , VecBB->getNumSuccessors ());
5757  EXPECT_EQ (VecBB->getParent ()->getEntryBasicBlock (), VecBB);
5858  EXPECT_EQ (&*Plan, VecBB->getPlan ());
5959
60-   VPBlockBase *VecLatch = VecBB->getSingleSuccessor ();
61-   EXPECT_EQ (VecLatch->getParent ()->getExitingBasicBlock (), VecLatch);
62-   EXPECT_EQ (0u , VecLatch->getNumSuccessors ());
63- 
6460  auto  Iter = VecBB->begin ();
6561  VPWidenPHIRecipe *Phi = dyn_cast<VPWidenPHIRecipe>(&*Iter++);
6662  EXPECT_NE (nullptr , Phi);
@@ -130,33 +126,28 @@ compound=true
130126      "  EMIT store ir\<%res\>, ir\<%arr.idx\>\l" + 
131127      "  EMIT ir\<%indvars.iv.next\> = add ir\<%indvars.iv\>, ir\<1\>\l" + 
132128      "  EMIT ir\<%exitcond\> = icmp ir\<%indvars.iv.next\>, ir\<%N\>\l" + 
133-       "Successor(s): vector.latch\l" 
134-     ] 
135-     N2 -> N4 [ label=""] 
136-     N4 [label = 
137-       "vector.latch:\l" + 
138129      "No successors\l" 
139130    ] 
140131  } 
141-   N4  -> N5  [ label="" ltail=cluster_N3] 
142-   N5  [label = 
132+   N2  -> N4  [ label="" ltail=cluster_N3] 
133+   N4  [label = 
143134    "middle.block:\l" + 
144135    "  EMIT vp\<%cmp.n\> = icmp eq ir\<%N\>, vp\<%0\>\l" + 
145136    "  EMIT branch-on-cond vp\<%cmp.n\>\l" + 
146137    "Successor(s): ir-bb\<for.end\>, scalar.ph\l" 
147138  ] 
148-   N5  -> N6  [ label="T"] 
149-   N5  -> N7  [ label="F"] 
150-   N6  [label = 
139+   N4  -> N5  [ label="T"] 
140+   N4  -> N6  [ label="F"] 
141+   N5  [label = 
151142    "ir-bb\<for.end\>:\l" + 
152143    "No successors\l" 
153144  ] 
154-   N7  [label = 
145+   N6  [label = 
155146    "scalar.ph:\l" + 
156147    "Successor(s): ir-bb\<for.body\>\l" 
157148  ] 
158-   N7  -> N8  [ label=""] 
159-   N8  [label = 
149+   N6  -> N7  [ label=""] 
150+   N7  [label = 
160151    "ir-bb\<for.body\>:\l" + 
161152    "  IR   %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]\l" + 
162153    "  IR   %arr.idx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv\l" + 
@@ -171,10 +162,6 @@ compound=true
171162)"  ;
172163  EXPECT_EQ (ExpectedStr, FullDump);
173164#endif 
174-   TargetLibraryInfoImpl TLII (M.getTargetTriple ());
175-   TargetLibraryInfo TLI (TLII);
176-   VPlanTransforms::tryToConvertVPInstructionsToVPRecipes (
177-       Plan, [](PHINode *P) { return  nullptr ; }, *SE, TLI);
178165}
179166
180167TEST_F (VPlanHCFGTest, testVPInstructionToVPRecipesInner) {
@@ -203,6 +190,12 @@ TEST_F(VPlanHCFGTest, testVPInstructionToVPRecipesInner) {
203190
204191  TargetLibraryInfoImpl TLII (M.getTargetTriple ());
205192  TargetLibraryInfo TLI (TLII);
193+   //  Current VPlan construction doesn't add a terminator for top-level loop
194+   //  latches. Add it before running transform.
195+   cast<VPBasicBlock>(Plan->getVectorLoopRegion ()->getExiting ())
196+       ->appendRecipe (new  VPInstruction (
197+           VPInstruction::BranchOnCond,
198+           {Plan->getOrAddLiveIn (ConstantInt::getTrue (F->getContext ()))}));
206199  VPlanTransforms::tryToConvertVPInstructionsToVPRecipes (
207200      Plan, [](PHINode *P) { return  nullptr ; }, *SE, TLI);
208201
@@ -214,15 +207,11 @@ TEST_F(VPlanHCFGTest, testVPInstructionToVPRecipesInner) {
214207  //  Check that the region following the preheader consists of a block for the
215208  //  original header and a separate latch.
216209  VPBasicBlock *VecBB = Plan->getVectorLoopRegion ()->getEntryBasicBlock ();
217-   EXPECT_EQ (7u , VecBB->size ());
210+   EXPECT_EQ (8u , VecBB->size ());
218211  EXPECT_EQ (0u , VecBB->getNumPredecessors ());
219-   EXPECT_EQ (1u , VecBB->getNumSuccessors ());
212+   EXPECT_EQ (0u , VecBB->getNumSuccessors ());
220213  EXPECT_EQ (VecBB->getParent ()->getEntryBasicBlock (), VecBB);
221214
222-   VPBlockBase *VecLatch = VecBB->getSingleSuccessor ();
223-   EXPECT_EQ (VecLatch->getParent ()->getExitingBasicBlock (), VecLatch);
224-   EXPECT_EQ (0u , VecLatch->getNumSuccessors ());
225- 
226215  auto  Iter = VecBB->begin ();
227216  EXPECT_NE (nullptr , dyn_cast<VPWidenPHIRecipe>(&*Iter++));
228217  EXPECT_NE (nullptr , dyn_cast<VPWidenGEPRecipe>(&*Iter++));
@@ -231,6 +220,7 @@ TEST_F(VPlanHCFGTest, testVPInstructionToVPRecipesInner) {
231220  EXPECT_NE (nullptr , dyn_cast<VPWidenMemoryRecipe>(&*Iter++));
232221  EXPECT_NE (nullptr , dyn_cast<VPWidenRecipe>(&*Iter++));
233222  EXPECT_NE (nullptr , dyn_cast<VPWidenRecipe>(&*Iter++));
223+   EXPECT_NE (nullptr , dyn_cast<VPInstruction>(&*Iter++));
234224  EXPECT_EQ (VecBB->end (), Iter);
235225}
236226
@@ -303,33 +293,28 @@ compound=true
303293      "  EMIT store ir\<%res\>, ir\<%arr.idx\>\l" + 
304294      "  EMIT ir\<%iv.next\> = add ir\<%iv\>, ir\<1\>\l" + 
305295      "  EMIT ir\<%exitcond\> = icmp ir\<%iv.next\>, ir\<%N\>\l" + 
306-       "Successor(s): vector.latch\l" 
307-     ] 
308-     N4 -> N5 [ label=""] 
309-     N5 [label = 
310-       "vector.latch:\l" + 
311296      "No successors\l" 
312297    ] 
313298  } 
314-   N5  -> N6  [ label="" ltail=cluster_N3] 
315-   N6  [label = 
299+   N4  -> N5  [ label="" ltail=cluster_N3] 
300+   N5  [label = 
316301    "middle.block:\l" + 
317302    "  EMIT vp\<%cmp.n\> = icmp eq ir\<%N\>, vp\<%0\>\l" + 
318303    "  EMIT branch-on-cond vp\<%cmp.n\>\l" + 
319304    "Successor(s): ir-bb\<exit.2\>, scalar.ph\l" 
320305  ] 
321-   N6  -> N7  [ label="T"] 
322-   N6  -> N8  [ label="F"] 
323-   N7  [label = 
306+   N5  -> N6  [ label="T"] 
307+   N5  -> N7  [ label="F"] 
308+   N6  [label = 
324309    "ir-bb\<exit.2\>:\l" + 
325310    "No successors\l" 
326311  ] 
327-   N8  [label = 
312+   N7  [label = 
328313    "scalar.ph:\l" + 
329314    "Successor(s): ir-bb\<loop.header\>\l" 
330315  ] 
331-   N8  -> N9  [ label=""] 
332-   N9  [label = 
316+   N7  -> N8  [ label=""] 
317+   N8  [label = 
333318    "ir-bb\<loop.header\>:\l" + 
334319    "  IR   %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\l" + 
335320    "  IR   %arr.idx = getelementptr inbounds i32, ptr %A, i64 %iv\l" + 
0 commit comments