From 650050c7c2061ec08da359b57e12ae7a4b8c8911 Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Mon, 12 Dec 2016 14:57:11 +0000 Subject: [PATCH] [SCEVExpander] Add a test case related to r289412 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289435 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/Analysis/ScalarEvolutionTest.cpp | 38 +++++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/unittests/Analysis/ScalarEvolutionTest.cpp b/unittests/Analysis/ScalarEvolutionTest.cpp index 1e1993843bb..2f509fd7e1b 100644 --- a/unittests/Analysis/ScalarEvolutionTest.cpp +++ b/unittests/Analysis/ScalarEvolutionTest.cpp @@ -51,13 +51,21 @@ protected: return ScalarEvolution(F, TLI, *AC, *DT, *LI); } - void runWithFunctionAndSE( - Module &M, StringRef FuncName, - function_ref Test) { + void runSCEVTest(Module &M, StringRef FuncName, + function_ref + Test) { auto *F = M.getFunction(FuncName); ASSERT_NE(F, nullptr) << "Could not find " << FuncName; ScalarEvolution SE = buildSE(*F); - Test(*F, SE); + Test(*F, *DT, *LI, SE); + } + + void runWithFunctionAndSE( + Module &M, StringRef FuncName, + function_ref Test) { + runSCEVTest(M, FuncName, [&](Function &F, DominatorTree &DT, LoopInfo &LI, + ScalarEvolution &SE) { Test(F, SE); }); } }; @@ -579,7 +587,8 @@ TEST_F(ScalarEvolutionsTest, BadHoistingSCEVExpander_PR30942) { assert(M && "Could not parse module?"); assert(!verifyModule(*M) && "Must have been well formed!"); - runWithFunctionAndSE(*M, "f_1", [&](Function &F, ScalarEvolution &SE) { + runSCEVTest(*M, "f_1", [&](Function &F, DominatorTree &DT, LoopInfo &LI, + ScalarEvolution &SE) { SCEVExpander Expander(SE, M->getDataLayout(), "unittests"); auto *DivInst = getInstructionByName(F, "div"); @@ -605,6 +614,25 @@ TEST_F(ScalarEvolutionsTest, BadHoistingSCEVExpander_PR30942) { ASSERT_NE(DivFromScratchExpansionInst, nullptr); EXPECT_EQ(DivInst->getParent(), DivFromScratchExpansionInst->getParent()); } + + { + auto *ArgY = getArgByName(F, "y"); + auto *One = SE.getOne(ArgY->getType()); + auto *DivFromScratchSCEV = SE.getUDivExpr(One, SE.getSCEV(ArgY)); + auto *L = LI.getLoopFor(DivInst->getParent()); + auto *ARFromScratchSCEV = + SE.getAddRecExpr(DivFromScratchSCEV, One, L, SCEV::FlagAnyWrap); + + Expander.disableCanonicalMode(); + + auto *ARFromScratchExpansion = Expander.expandCodeFor( + ARFromScratchSCEV, ARFromScratchSCEV->getType(), + DivInst->getParent()->getTerminator()); + auto *ARFromScratchExpansionInst = + dyn_cast(ARFromScratchExpansion); + ASSERT_NE(ARFromScratchExpansionInst, nullptr); + ASSERT_FALSE(verifyFunction(F)); + } }); } -- 2.50.0