diff options
author | Dan Gohman <gohman@apple.com> | 2010-07-29 00:17:55 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-07-29 00:17:55 +0000 |
commit | c6743207e20904008d2de016adfa6b0a9355c0e7 (patch) | |
tree | 8f727d234ed249b9d463ddf3c4658401a81dd93a /unittests/Analysis/ScalarEvolutionTest.cpp | |
parent | e2fb451dbb50d9b1b4254f5acc7c98b1a8ebd3cf (diff) |
Factor out some of the code for updating old SCEVUnknown values, and
extend it to handle the case where multiple RAUWs affect a single
SCEVUnknown.
Add a ScalarEvolution unittest to test for this situation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109705 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Analysis/ScalarEvolutionTest.cpp')
-rw-r--r-- | unittests/Analysis/ScalarEvolutionTest.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/unittests/Analysis/ScalarEvolutionTest.cpp b/unittests/Analysis/ScalarEvolutionTest.cpp new file mode 100644 index 0000000000..19bf90f073 --- /dev/null +++ b/unittests/Analysis/ScalarEvolutionTest.cpp @@ -0,0 +1,78 @@ +//===- ScalarEvolutionsTest.cpp - ScalarEvolution unit tests --------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <llvm/Analysis/ScalarEvolutionExpressions.h> +#include <llvm/GlobalVariable.h> +#include <llvm/Constants.h> +#include <llvm/LLVMContext.h> +#include <llvm/Module.h> +#include <llvm/PassManager.h> +#include "gtest/gtest.h" + +namespace llvm { +namespace { + +TEST(ScalarEvolutionsTest, ReturnInst) { + LLVMContext Context; + Module M("world", Context); + + const FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), + std::vector<const Type *>(), false); + Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); + BasicBlock *BB = BasicBlock::Create(Context, "entry", F); + ReturnInst::Create(Context, 0, BB); + + const Type *Ty = Type::getInt1Ty(Context); + Constant *Init = Constant::getNullValue(Ty); + Value *V0 = new GlobalVariable(M, Ty, false, GlobalValue::ExternalLinkage, Init, "V0"); + Value *V1 = new GlobalVariable(M, Ty, false, GlobalValue::ExternalLinkage, Init, "V1"); + Value *V2 = new GlobalVariable(M, Ty, false, GlobalValue::ExternalLinkage, Init, "V2"); + + // Create a ScalarEvolution and "run" it so that it gets initialized. + PassManager PM; + ScalarEvolution &SE = *new ScalarEvolution(); + PM.add(&SE); + PM.run(M); + + const SCEV *S0 = SE.getSCEV(V0); + const SCEV *S1 = SE.getSCEV(V1); + const SCEV *S2 = SE.getSCEV(V2); + + const SCEV *P0 = SE.getAddExpr(S0, S0); + const SCEV *P1 = SE.getAddExpr(S1, S1); + const SCEV *P2 = SE.getAddExpr(S2, S2); + + const SCEVMulExpr *M0 = cast<SCEVMulExpr>(P0); + const SCEVMulExpr *M1 = cast<SCEVMulExpr>(P1); + const SCEVMulExpr *M2 = cast<SCEVMulExpr>(P2); + + EXPECT_EQ(cast<SCEVConstant>(M0->getOperand(0))->getValue()->getZExtValue(), + 2u); + EXPECT_EQ(cast<SCEVConstant>(M1->getOperand(0))->getValue()->getZExtValue(), + 2u); + EXPECT_EQ(cast<SCEVConstant>(M2->getOperand(0))->getValue()->getZExtValue(), + 2u); + + // Before the RAUWs, these are all pointing to separate values. + EXPECT_EQ(cast<SCEVUnknown>(M0->getOperand(1))->getValue(), V0); + EXPECT_EQ(cast<SCEVUnknown>(M1->getOperand(1))->getValue(), V1); + EXPECT_EQ(cast<SCEVUnknown>(M2->getOperand(1))->getValue(), V2); + + // Do some RAUWs. + V2->replaceAllUsesWith(V1); + V1->replaceAllUsesWith(V0); + + // After the RAUWs, these should all be pointing to V0. + EXPECT_EQ(cast<SCEVUnknown>(M0->getOperand(1))->getValue(), V0); + EXPECT_EQ(cast<SCEVUnknown>(M1->getOperand(1))->getValue(), V0); + EXPECT_EQ(cast<SCEVUnknown>(M2->getOperand(1))->getValue(), V0); +} + +} // end anonymous namespace +} // end namespace llvm |