summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2016-12-12 18:52:32 +0000
committerReid Kleckner <rnk@google.com>2016-12-12 18:52:32 +0000
commit30422eea0f9341a77a871addb31f8a12806ea18a (patch)
treeaf67e39986023907048515b64f3dfc93c9f904f8 /llvm/unittests/Analysis/ScalarEvolutionTest.cpp
parent4881bdf1413aed8163e96c01e12f416cb61908a1 (diff)
downloadbcm5719-llvm-30422eea0f9341a77a871addb31f8a12806ea18a.tar.gz
bcm5719-llvm-30422eea0f9341a77a871addb31f8a12806ea18a.zip
Revert "[SCEVExpand] do not hoist divisions by zero (PR30935)"
Reverts r289412. It caused an OOB PHI operand access in instcombine when ASan is enabled. Reduction in progress. Also reverts "[SCEVExpander] Add a test case related to r289412" llvm-svn: 289453
Diffstat (limited to 'llvm/unittests/Analysis/ScalarEvolutionTest.cpp')
-rw-r--r--llvm/unittests/Analysis/ScalarEvolutionTest.cpp112
1 files changed, 4 insertions, 108 deletions
diff --git a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
index 2f509fd7e1b..752cc812824 100644
--- a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
+++ b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
@@ -51,21 +51,13 @@ protected:
return ScalarEvolution(F, TLI, *AC, *DT, *LI);
}
- 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, *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); });
+ auto *F = M.getFunction(FuncName);
+ ASSERT_NE(F, nullptr) << "Could not find " << FuncName;
+ ScalarEvolution SE = buildSE(*F);
+ Test(*F, SE);
}
};
@@ -357,13 +349,6 @@ static Instruction *getInstructionByName(Function &F, StringRef Name) {
llvm_unreachable("Expected to find instruction!");
}
-static Argument *getArgByName(Function &F, StringRef Name) {
- for (auto &A : F.args())
- if (A.getName() == Name)
- return &A;
- llvm_unreachable("Expected to find argument!");
-}
-
TEST_F(ScalarEvolutionsTest, CommutativeExprOperandOrder) {
LLVMContext C;
SMDiagnostic Err;
@@ -547,94 +532,5 @@ TEST_F(ScalarEvolutionsTest, SCEVCompareComplexity) {
EXPECT_NE(nullptr, SE.getSCEV(Acc[0]));
}
-TEST_F(ScalarEvolutionsTest, BadHoistingSCEVExpander_PR30942) {
- LLVMContext C;
- SMDiagnostic Err;
- std::unique_ptr<Module> M = parseAssemblyString(
- "target datalayout = \"e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128\" "
- " "
- "define void @f_1(i32 %x, i32 %y, i32 %n, i1* %cond_buf) "
- " local_unnamed_addr { "
- "entry: "
- " %entrycond = icmp sgt i32 %n, 0 "
- " br i1 %entrycond, label %loop.ph, label %for.end "
- " "
- "loop.ph: "
- " br label %loop "
- " "
- "loop: "
- " %iv1 = phi i32 [ %iv1.inc, %right ], [ 0, %loop.ph ] "
- " %iv1.inc = add nuw nsw i32 %iv1, 1 "
- " %cond = load volatile i1, i1* %cond_buf "
- " br i1 %cond, label %left, label %right "
- " "
- "left: "
- " %div = udiv i32 %x, %y "
- " br label %right "
- " "
- "right: "
- " %exitcond = icmp eq i32 %iv1.inc, %n "
- " br i1 %exitcond, label %for.end.loopexit, label %loop "
- " "
- "for.end.loopexit: "
- " br label %for.end "
- " "
- "for.end: "
- " ret void "
- "} ",
- Err, C);
-
- assert(M && "Could not parse module?");
- assert(!verifyModule(*M) && "Must have been well formed!");
-
- runSCEVTest(*M, "f_1", [&](Function &F, DominatorTree &DT, LoopInfo &LI,
- ScalarEvolution &SE) {
- SCEVExpander Expander(SE, M->getDataLayout(), "unittests");
- auto *DivInst = getInstructionByName(F, "div");
-
- {
- auto *DivSCEV = SE.getSCEV(DivInst);
- auto *DivExpansion = Expander.expandCodeFor(
- DivSCEV, DivSCEV->getType(), DivInst->getParent()->getTerminator());
- auto *DivExpansionInst = dyn_cast<Instruction>(DivExpansion);
- ASSERT_NE(DivExpansionInst, nullptr);
- EXPECT_EQ(DivInst->getParent(), DivExpansionInst->getParent());
- }
-
- {
- auto *ArgY = getArgByName(F, "y");
- auto *DivFromScratchSCEV =
- SE.getUDivExpr(SE.getOne(ArgY->getType()), SE.getSCEV(ArgY));
-
- auto *DivFromScratchExpansion = Expander.expandCodeFor(
- DivFromScratchSCEV, DivFromScratchSCEV->getType(),
- DivInst->getParent()->getTerminator());
- auto *DivFromScratchExpansionInst =
- dyn_cast<Instruction>(DivFromScratchExpansion);
- 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));
- }
- });
-}
-
} // end anonymous namespace
} // end namespace llvm
OpenPOWER on IntegriCloud