[llvm-commits] [llvm] r164582 - in /llvm/trunk/unittests/Transforms/Utils: CMakeLists.txt IntegerDivision.cpp
Michael Ilseman
milseman at apple.com
Mon Sep 24 18:33:33 PDT 2012
Author: milseman
Date: Mon Sep 24 20:33:33 2012
New Revision: 164582
URL: http://llvm.org/viewvc/llvm-project?rev=164582&view=rev
Log:
Unit tests for IntegerDivision. Currently, just a basic sanity check to ensure that the code was generated properly. Future work would be finding some way to test the actual result that would be computed.
Added:
llvm/trunk/unittests/Transforms/Utils/IntegerDivision.cpp
Modified:
llvm/trunk/unittests/Transforms/Utils/CMakeLists.txt
Modified: llvm/trunk/unittests/Transforms/Utils/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Utils/CMakeLists.txt?rev=164582&r1=164581&r2=164582&view=diff
==============================================================================
--- llvm/trunk/unittests/Transforms/Utils/CMakeLists.txt (original)
+++ llvm/trunk/unittests/Transforms/Utils/CMakeLists.txt Mon Sep 24 20:33:33 2012
@@ -4,5 +4,6 @@
add_llvm_unittest(UtilsTests
Cloning.cpp
+ IntegerDivision.cpp
Local.cpp
)
Added: llvm/trunk/unittests/Transforms/Utils/IntegerDivision.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Utils/IntegerDivision.cpp?rev=164582&view=auto
==============================================================================
--- llvm/trunk/unittests/Transforms/Utils/IntegerDivision.cpp (added)
+++ llvm/trunk/unittests/Transforms/Utils/IntegerDivision.cpp Mon Sep 24 20:33:33 2012
@@ -0,0 +1,54 @@
+//===- IntegerDivision.cpp - Unit tests for the integer division code -----===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/BasicBlock.h"
+#include "llvm/GlobalValue.h"
+#include "llvm/Function.h"
+#include "llvm/IRBuilder.h"
+#include "llvm/Module.h"
+#include "llvm/Transforms/Utils/IntegerDivision.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(IntegerDivision, SDiv) {
+ 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.CreateSDiv(A, B);
+ EXPECT_TRUE(BB->front().getOpcode() == Instruction::SDiv);
+
+ Value *Ret = Builder.CreateRet(Div);
+
+ expandDivision(cast<BinaryOperator>(Div));
+ EXPECT_TRUE(BB->front().getOpcode() == Instruction::AShr);
+
+ Instruction* Quotient = dyn_cast<Instruction>(cast<User>(Ret)->getOperand(0));
+ EXPECT_TRUE(Quotient && Quotient->getOpcode() == Instruction::Sub);
+
+ Builder.SetInsertPoint(BB->end());
+}
+
+}
More information about the llvm-commits
mailing list