llvm.org GIT mirror llvm / 650050c
[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 Sanjoy Das 2 years ago
1 changed file(s) with 33 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
5050 return ScalarEvolution(F, TLI, *AC, *DT, *LI);
5151 }
5252
53 void runSCEVTest(Module &M, StringRef FuncName,
54 function_ref
55 LoopInfo &LI, ScalarEvolution &SE)>
56 Test) {
57 auto *F = M.getFunction(FuncName);
58 ASSERT_NE(F, nullptr) << "Could not find " << FuncName;
59 ScalarEvolution SE = buildSE(*F);
60 Test(*F, *DT, *LI, SE);
61 }
62
5363 void runWithFunctionAndSE(
5464 Module &M, StringRef FuncName,
5565 function_ref Test) {
56 auto *F = M.getFunction(FuncName);
57 ASSERT_NE(F, nullptr) << "Could not find " << FuncName;
58 ScalarEvolution SE = buildSE(*F);
59 Test(*F, SE);
66 runSCEVTest(M, FuncName, [&](Function &F, DominatorTree &DT, LoopInfo &LI,
67 ScalarEvolution &SE) { Test(F, SE); });
6068 }
6169 };
6270
578586 assert(M && "Could not parse module?");
579587 assert(!verifyModule(*M) && "Must have been well formed!");
580588
581 runWithFunctionAndSE(*M, "f_1", [&](Function &F, ScalarEvolution &SE) {
589 runSCEVTest(*M, "f_1", [&](Function &F, DominatorTree &DT, LoopInfo &LI,
590 ScalarEvolution &SE) {
582591 SCEVExpander Expander(SE, M->getDataLayout(), "unittests");
583592 auto *DivInst = getInstructionByName(F, "div");
584593
604613 ASSERT_NE(DivFromScratchExpansionInst, nullptr);
605614 EXPECT_EQ(DivInst->getParent(), DivFromScratchExpansionInst->getParent());
606615 }
616
617 {
618 auto *ArgY = getArgByName(F, "y");
619 auto *One = SE.getOne(ArgY->getType());
620 auto *DivFromScratchSCEV = SE.getUDivExpr(One, SE.getSCEV(ArgY));
621 auto *L = LI.getLoopFor(DivInst->getParent());
622 auto *ARFromScratchSCEV =
623 SE.getAddRecExpr(DivFromScratchSCEV, One, L, SCEV::FlagAnyWrap);
624
625 Expander.disableCanonicalMode();
626
627 auto *ARFromScratchExpansion = Expander.expandCodeFor(
628 ARFromScratchSCEV, ARFromScratchSCEV->getType(),
629 DivInst->getParent()->getTerminator());
630 auto *ARFromScratchExpansionInst =
631 dyn_cast(ARFromScratchExpansion);
632 ASSERT_NE(ARFromScratchExpansionInst, nullptr);
633 ASSERT_FALSE(verifyFunction(F));
634 }
607635 });
608636 }
609637