summaryrefslogtreecommitdiff
path: root/unittests/Analysis/ScalarEvolutionTest.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-03-09 22:50:27 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-03-09 22:50:27 +0000
commit31bbf64f3a4974a2d6c8b3b27ad2f519caf74057 (patch)
tree0d37937ef37e76e4d410039516390662899f7caa /unittests/Analysis/ScalarEvolutionTest.cpp
parent365919ebc13fcd6ddae24bfcc7c4720dc682c78b (diff)
Notes
Diffstat (limited to 'unittests/Analysis/ScalarEvolutionTest.cpp')
-rw-r--r--unittests/Analysis/ScalarEvolutionTest.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/unittests/Analysis/ScalarEvolutionTest.cpp b/unittests/Analysis/ScalarEvolutionTest.cpp
index 752cc8128248..f4370842edb5 100644
--- a/unittests/Analysis/ScalarEvolutionTest.cpp
+++ b/unittests/Analysis/ScalarEvolutionTest.cpp
@@ -465,7 +465,7 @@ TEST_F(ScalarEvolutionsTest, CommutativeExprOperandOrder) {
});
}
-TEST_F(ScalarEvolutionsTest, SCEVCompareComplexity) {
+TEST_F(ScalarEvolutionsTest, CompareSCEVComplexity) {
FunctionType *FTy =
FunctionType::get(Type::getVoidTy(Context), std::vector<Type *>(), false);
Function *F = cast<Function>(M.getOrInsertFunction("f", FTy));
@@ -532,5 +532,41 @@ TEST_F(ScalarEvolutionsTest, SCEVCompareComplexity) {
EXPECT_NE(nullptr, SE.getSCEV(Acc[0]));
}
+TEST_F(ScalarEvolutionsTest, CompareValueComplexity) {
+ IntegerType *IntPtrTy = M.getDataLayout().getIntPtrType(Context);
+ PointerType *IntPtrPtrTy = IntPtrTy->getPointerTo();
+
+ FunctionType *FTy =
+ FunctionType::get(Type::getVoidTy(Context), {IntPtrTy, IntPtrTy}, false);
+ Function *F = cast<Function>(M.getOrInsertFunction("f", FTy));
+ BasicBlock *EntryBB = BasicBlock::Create(Context, "entry", F);
+
+ Value *X = &*F->arg_begin();
+ Value *Y = &*std::next(F->arg_begin());
+
+ const int ValueDepth = 10;
+ for (int i = 0; i < ValueDepth; i++) {
+ X = new LoadInst(new IntToPtrInst(X, IntPtrPtrTy, "", EntryBB), "",
+ /*isVolatile*/ false, EntryBB);
+ Y = new LoadInst(new IntToPtrInst(Y, IntPtrPtrTy, "", EntryBB), "",
+ /*isVolatile*/ false, EntryBB);
+ }
+
+ auto *MulA = BinaryOperator::CreateMul(X, Y, "", EntryBB);
+ auto *MulB = BinaryOperator::CreateMul(Y, X, "", EntryBB);
+ ReturnInst::Create(Context, nullptr, EntryBB);
+
+ // This test isn't checking for correctness. Today making A and B resolve to
+ // the same SCEV would require deeper searching in CompareValueComplexity,
+ // which will slow down compilation. However, this test can fail (with LLVM's
+ // behavior still being correct) if we ever have a smarter
+ // CompareValueComplexity that is both fast and more accurate.
+
+ ScalarEvolution SE = buildSE(*F);
+ auto *A = SE.getSCEV(MulA);
+ auto *B = SE.getSCEV(MulB);
+ EXPECT_NE(A, B);
+}
+
} // end anonymous namespace
} // end namespace llvm