diff options
author | Michael Ilseman <milseman@apple.com> | 2012-09-25 17:56:47 +0000 |
---|---|---|
committer | Michael Ilseman <milseman@apple.com> | 2012-09-25 17:56:47 +0000 |
commit | 13098443994339249fb3f085bbc4fbcdf9f033db (patch) | |
tree | 9499c4e27786d1e1d1957f38550c55d46d96e36d /unittests/Transforms | |
parent | a3c3e1f8e2dc3572564426a420c293a271630c7b (diff) | |
download | external_llvm-13098443994339249fb3f085bbc4fbcdf9f033db.zip external_llvm-13098443994339249fb3f085bbc4fbcdf9f033db.tar.gz external_llvm-13098443994339249fb3f085bbc4fbcdf9f033db.tar.bz2 |
Expansions for u/srem, using the udiv expansion. More unit tests for udiv and u/srem.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164614 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Transforms')
-rw-r--r-- | unittests/Transforms/Utils/IntegerDivision.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/unittests/Transforms/Utils/IntegerDivision.cpp b/unittests/Transforms/Utils/IntegerDivision.cpp index a026b34..ff90e6b 100644 --- a/unittests/Transforms/Utils/IntegerDivision.cpp +++ b/unittests/Transforms/Utils/IntegerDivision.cpp @@ -51,4 +51,101 @@ TEST(IntegerDivision, SDiv) { Builder.SetInsertPoint(BB->end()); } +TEST(IntegerDivision, UDiv) { + LLVMContext &C(getGlobalContext()); + Module M("test division", C); + IRBuilder<> Builder(C); + + SmallVector<Type*, 2> ArgTys(2, Builder.getInt32Ty()); + Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(), + ArgTys, false), + GlobalValue::ExternalLinkage, "F", &M); + assert(F->getArgumentList().size() == 2); + + BasicBlock *BB = BasicBlock::Create(C, "", F); + Builder.SetInsertPoint(BB); + + Function::arg_iterator AI = F->arg_begin(); + Value *A = AI++; + Value *B = AI++; + + Value *Div = Builder.CreateUDiv(A, B); + EXPECT_TRUE(BB->front().getOpcode() == Instruction::UDiv); + + Value *Ret = Builder.CreateRet(Div); + + expandDivision(cast<BinaryOperator>(Div)); + EXPECT_TRUE(BB->front().getOpcode() == Instruction::ICmp); + + Instruction* Quotient = dyn_cast<Instruction>(cast<User>(Ret)->getOperand(0)); + EXPECT_TRUE(Quotient && Quotient->getOpcode() == Instruction::PHI); + + Builder.SetInsertPoint(BB->end()); +} + + +TEST(IntegerDivision, SRem) { + LLVMContext &C(getGlobalContext()); + Module M("test remainder", C); + IRBuilder<> Builder(C); + + SmallVector<Type*, 2> ArgTys(2, Builder.getInt32Ty()); + Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(), + ArgTys, false), + GlobalValue::ExternalLinkage, "F", &M); + assert(F->getArgumentList().size() == 2); + + BasicBlock *BB = BasicBlock::Create(C, "", F); + Builder.SetInsertPoint(BB); + + Function::arg_iterator AI = F->arg_begin(); + Value *A = AI++; + Value *B = AI++; + + Value *Rem = Builder.CreateSRem(A, B); + EXPECT_TRUE(BB->front().getOpcode() == Instruction::SRem); + + Value *Ret = Builder.CreateRet(Rem); + + expandRemainder(cast<BinaryOperator>(Rem)); + EXPECT_TRUE(BB->front().getOpcode() == Instruction::AShr); + + Instruction* Remainder = dyn_cast<Instruction>(cast<User>(Ret)->getOperand(0)); + EXPECT_TRUE(Remainder && Remainder->getOpcode() == Instruction::Sub); + + Builder.SetInsertPoint(BB->end()); +} + +TEST(IntegerDivision, URem) { + LLVMContext &C(getGlobalContext()); + Module M("test remainder", C); + IRBuilder<> Builder(C); + + SmallVector<Type*, 2> ArgTys(2, Builder.getInt32Ty()); + Function *F = Function::Create(FunctionType::get(Builder.getInt32Ty(), + ArgTys, false), + GlobalValue::ExternalLinkage, "F", &M); + assert(F->getArgumentList().size() == 2); + + BasicBlock *BB = BasicBlock::Create(C, "", F); + Builder.SetInsertPoint(BB); + + Function::arg_iterator AI = F->arg_begin(); + Value *A = AI++; + Value *B = AI++; + + Value *Rem = Builder.CreateURem(A, B); + EXPECT_TRUE(BB->front().getOpcode() == Instruction::URem); + + Value *Ret = Builder.CreateRet(Rem); + + expandRemainder(cast<BinaryOperator>(Rem)); + EXPECT_TRUE(BB->front().getOpcode() == Instruction::ICmp); + + Instruction* Remainder = dyn_cast<Instruction>(cast<User>(Ret)->getOperand(0)); + EXPECT_TRUE(Remainder && Remainder->getOpcode() == Instruction::Sub); + + Builder.SetInsertPoint(BB->end()); +} + } |