[llvm] r289435 - [SCEVExpander] Add a test case related to r289412

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 06:57:11 PST 2016


Author: sanjoy
Date: Mon Dec 12 08:57:11 2016
New Revision: 289435

URL: http://llvm.org/viewvc/llvm-project?rev=289435&view=rev
Log:
[SCEVExpander] Add a test case related to r289412

Modified:
    llvm/trunk/unittests/Analysis/ScalarEvolutionTest.cpp

Modified: llvm/trunk/unittests/Analysis/ScalarEvolutionTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/ScalarEvolutionTest.cpp?rev=289435&r1=289434&r2=289435&view=diff
==============================================================================
--- llvm/trunk/unittests/Analysis/ScalarEvolutionTest.cpp (original)
+++ llvm/trunk/unittests/Analysis/ScalarEvolutionTest.cpp Mon Dec 12 08:57:11 2016
@@ -51,13 +51,21 @@ protected:
     return ScalarEvolution(F, TLI, *AC, *DT, *LI);
   }
 
-  void runWithFunctionAndSE(
-      Module &M, StringRef FuncName,
-      function_ref<void(Function &F, ScalarEvolution &SE)> Test) {
+  void runSCEVTest(Module &M, StringRef FuncName,
+                   function_ref<void(Function &F, DominatorTree &DT,
+                                     LoopInfo &LI, ScalarEvolution &SE)>
+                       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<void(Function &F, ScalarEvolution &SE)> Test) {
+    runSCEVTest(M, FuncName, [&](Function &F, DominatorTree &DT, LoopInfo &LI,
+                                 ScalarEvolution &SE) { Test(F, SE); });
   }
 };
 
@@ -579,7 +587,8 @@ TEST_F(ScalarEvolutionsTest, BadHoisting
   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, BadHoisting
       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<Instruction>(ARFromScratchExpansion);
+      ASSERT_NE(ARFromScratchExpansionInst, nullptr);
+      ASSERT_FALSE(verifyFunction(F));
+    }
   });
 }
 




More information about the llvm-commits mailing list