From f1ee04c42a431d88cd66b884570ca7928cffd0cd Mon Sep 17 00:00:00 2001 From: Serguei Katkov Date: Mon, 15 Jul 2019 05:51:10 +0000 Subject: [LoopInfo] Introduce getUniqueNonLatchExitBlocks utility function Extract the code from LoopUnrollRuntime into utility function to re-use it in D63923. Reviewers: reames, mkuper Reviewed By: reames Subscribers: fhahn, hiraditya, zzheng, dmgreen, llvm-commits Differential Revision: https://reviews.llvm.org/D64548 llvm-svn: 366040 --- llvm/unittests/Analysis/LoopInfoTest.cpp | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'llvm/unittests/Analysis/LoopInfoTest.cpp') diff --git a/llvm/unittests/Analysis/LoopInfoTest.cpp b/llvm/unittests/Analysis/LoopInfoTest.cpp index 005e1dc405b..953a72aee8e 100644 --- a/llvm/unittests/Analysis/LoopInfoTest.cpp +++ b/llvm/unittests/Analysis/LoopInfoTest.cpp @@ -1110,3 +1110,49 @@ TEST(LoopInfoTest, AuxiliaryIV) { L->isAuxiliaryInductionVariable(Instruction_mulopcode, SE)); }); } + +// Examine getUniqueExitBlocks/getUniqueNonLatchExitBlocks functions. +TEST(LoopInfoTest, LoopUniqueExitBlocks) { + const char *ModuleStr = + "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n" + "define void @foo(i32 %n, i1 %cond) {\n" + "entry:\n" + " br label %for.cond\n" + "for.cond:\n" + " %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]\n" + " %cmp = icmp slt i32 %i.0, %n\n" + " br i1 %cond, label %for.inc, label %for.end1\n" + "for.inc:\n" + " %inc = add nsw i32 %i.0, 1\n" + " br i1 %cmp, label %for.cond, label %for.end2, !llvm.loop !0\n" + "for.end1:\n" + " br label %for.end\n" + "for.end2:\n" + " br label %for.end\n" + "for.end:\n" + " ret void\n" + "}\n" + "!0 = distinct !{!0, !1}\n" + "!1 = !{!\"llvm.loop.distribute.enable\", i1 true}\n"; + + // Parse the module. + LLVMContext Context; + std::unique_ptr M = makeLLVMModule(Context, ModuleStr); + + runWithLoopInfo(*M, "foo", [&](Function &F, LoopInfo &LI) { + Function::iterator FI = F.begin(); + // First basic block is entry - skip it. + BasicBlock *Header = &*(++FI); + assert(Header->getName() == "for.cond"); + Loop *L = LI.getLoopFor(Header); + + SmallVector Exits; + // This loop has 2 unique exits. + L->getUniqueExitBlocks(Exits); + EXPECT_TRUE(Exits.size() == 2); + // And one unique non latch exit. + Exits.clear(); + L->getUniqueNonLatchExitBlocks(Exits); + EXPECT_TRUE(Exits.size() == 1); + }); +} -- cgit v1.2.3